ASP.Net MVC 视图和控制器文件结构 [英] ASP.Net MVC View and Controller file structure

查看:72
本文介绍了ASP.Net MVC 视图和控制器文件结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑必须在 MVC 1.0 项目结构中设置 View 和相应的控制器.目前在默认应用程序中,我们在 Home 文件夹下有 About.aspx 页面,所有控制器操作都在 HomeController 中处理.这个控制器混合了 Home 动作和 About 动作.它使事情变得混乱.我喜欢清楚地分离我的控制器.喜欢分别有一个 About Controller 和 HomeCotroller.为此,我在视图文件夹下创建了另一个文件夹关于"并将 Aboput.aspx 放入其中,否则我们将收到以下错误.我怎样才能实现它?我喜欢像 View 一样有精确的文件夹结构,和 Cotroller 一样.

I am very confused the View and corresponding controller has to be set in MVC 1.0 project structure. Currently in a default application we have About.aspx page under Home folder and all the controller action is handled in HomeController. This controller mixes up Home action and About action. It makes things messy. I like to have clear separation of my controller. Like to have one About Controller and HomeCotroller separately. For it I have create another folder "About" under view folder and place Aboput.aspx in it , otherwise we will get the error below. How can I achieve it ?? I like to have exact folder structure as in View, same as in Cotroller.

The view 'About' or its master could not be found. The following locations were searched:
~/Views/About/About.aspx
~/Views/About/About.ascx
~/Views/Shared/About.aspx
~/Views/Shared/About.ascx 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The view 'About' or its master could not be found. The following locations were searched:
~/Views/About/About.aspx
~/Views/About/About.ascx
~/Views/Shared/About.aspx
~/Views/Shared/About.ascx

我喜欢像 \iew\About.aspx 和 Cotroller\AboutController.cs 这样的文件夹或 \View\Info\About.aspx 和 \Controller\Info\AboutController.cs.

I like to have folders like \iew\About.aspx and Cotroller\AboutController.cs or \View\Info\About.aspx and \Controller\Info\AboutController.cs.

这将使我的项目和代码非常干净且易于维护.预先感谢您的帮助

This will make my project and code very cleanly placed and good to maintain. Thanks in advance for helping

推荐答案

我想他们会希望你有

查看次数/关于/Index.aspx

Views/About/Index.aspx

哪个/Views/AboutController Index() 会指向

which /Views/AboutController Index() would point to

路由示例:

在 Global.asax 中:

in Global.asax:

protected void Application_Start()
{
    MyRoutes.RegisterRoutes(RouteTable.Routes);         
}

然后在 MyRoutes 类中:

then in the MyRoutes class:

public class MyRoutes
{
     internal static void RegisterRoutes(RouteCollection routes)
     {
         // add routes
     }
}

这篇关于ASP.Net MVC 视图和控制器文件结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆