# ------------------------------------------------
# This is the root of any IronPython based
# AspNet MVC application.
# ------------------------------------------------
import aspnet
# Define "root" class of the MVC-System
class App(aspnet.Application):
# Start IronPython asp.net mvc application.
# Routes and other stuff can be registered here
def start(self):
# Register all routes
aspnet.Routing.register_all()
# Set layout
aspnet.Views.set_layout('~/Views/Shared/_Layout.cshtml')
# Load style bundle
bundle = aspnet.StyleBundle('~/Content/css')
bundle.include("~/Content/css/all.css")
aspnet.Bundles.add(bundle)
class HomeController(aspnet.Controller):
def index(self):
return self.view("~/Views/Home/Index.cshtml")
def page(self):
# Works also with default paths
return self.view()
def paramSample(self, id, id2 = 'default-value for id2'):
# Works also with default paths
model = SampleModel()
model.id = id
model.id2 = id2
return self.view("~/Views/Home/ParamSample.cshtml", model)
@aspnet.Filter.httpPost
def postSample(self):
return self.view("~/Views/Home/Index.cshtml")
class SampleModel:
id = 0
id2 = ''
class ProductController(aspnet.Controller):
def index(self):
return self.view("~/Views/Product/Index.cshtml")
我正在做这个。它已经支持很多东西了:https://github.com/simplic-systems/ironpython-aspnet-mvc
更多信息:
导入
aspnet
模块你可以自己写控制器
您可以自动注册所有控制器
您可以使用不同的http方法
还有更多。下面是一个非常简短的例子
在ASP.NET MVC中使用IronPython:http://www.codevoyeur.com/Articles/Tags/ironpython.aspx
本页包含以下文章:
是的,there is an MVC example from the DLR team。
你也可能对Spark感兴趣。
相关问题 更多 >
编程相关推荐