如何减少MVC区域中的子文件夹数量?
我有一个 asp.net MVC3 应用程序,并且我正在使用 Areas。
默认情况下,我理解设置如下所示:
Areas\
Orders\
Controllers\
HomeController.cs (Action method: Index)
OrderController.cs (Action method: OrderIndex)
TransferController.cs (Action method: TransferIndex)
Views\
Home\
Index.aspx
Order\
OrderIndex.aspx
Transfer\
TransferIndex.aspx
我想做的只是文件夹的数量来执行类似的操作:
Areas\
Orders\
Controllers\
OrderController.cs (Action method: Index, OrderIndex, TransferIndex)
Views\
Index.aspx
OrderIndex.aspx
TransferIndex.aspx
这可能吗?这是路由设置吗?
I have an asp.net MVC3 application, and I'm using Areas.
By default, I understand the setup would look like this:
Areas\
Orders\
Controllers\
HomeController.cs (Action method: Index)
OrderController.cs (Action method: OrderIndex)
TransferController.cs (Action method: TransferIndex)
Views\
Home\
Index.aspx
Order\
OrderIndex.aspx
Transfer\
TransferIndex.aspx
What I would like to do is simply the number of folders to do something like this:
Areas\
Orders\
Controllers\
OrderController.cs (Action method: Index, OrderIndex, TransferIndex)
Views\
Index.aspx
OrderIndex.aspx
TransferIndex.aspx
Is this possible? Is this a routing setup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以编写自定义视图引擎。我将提供一个使用 Razor 的示例:
然后在
Application_Start
中注册此视图引擎:这几乎就是您实现所需目标所需的全部内容。
当然,如果您使用 WebForms 视图引擎,则需要进行一些细微的调整:
You could write a custom view engine. I will provide an example with Razor:
and then register this view engine in
Application_Start
:and that's pretty much all you're gonna need to achieve what you are looking for.
And of course if you are using the WebForms view engine slight adaptations are necessary: