开发者

ASP.Net MVC View and Controller file structure

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

I like to have folders like \iew\About.aspx and Cotroll开发者_如何学Goer\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


I think they would want you to have

Views/About/Index.aspx

which /Views/AboutController Index() would point to

Routing Example:

in Global.asax:

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

then in the MyRoutes class:

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


You should probably look at the basic tutorials for the ASP.Net MVC framework. It operates under several conventions - and one of the biggest conventions is the file naming and folder structure.

While the structure you like may be good for simple projects or your personal preference, it's not ideal for large projects. You need to either follow the convention, or learn enough about the framework so you can override the behavior of it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜