I have a MVC 5 project with lots of controllers, models and pages. For making them more maintainable i moved some of related files to a new area, called Mail.
The project structure is like:
Automation (project's name)
|- Controllers
|- Views
|- Models
└── Areas
└── Mail
└── Models
└── Controllers
└── MailboxController
└── Views
└── Inbox.cshtml
I did below steps to be able to load newly moved views:
- Change namespace of the controller in the Area -> Mail -> Controllers
Add Rout to the MailAreaRegistaration.cs as follow:
public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Mail_default", "Mail/{controller}/{action}/{id}", new { action = "Inbox", id = UrlParameter.Optional}, new [] { "Automation.Areas.Mail.Controllers" }); }
- RegisterAllAreaas() in the global.asax.cs
Change MapRout method in the project's RoutConfig file as below:
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Dashboards", action = "Dashboard_Main", id = UrlParameter.Optional }, namespaces: new [] {"Automation.Controllers"} ); }
All the pages that are in the main View folder rendered as expected, but when i want to load the inbox.cshtml in the Mail area this errors are shown:
The view 'inbox' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Areas/Mail/Views/mailbox/inbox.aspx
~/Areas/Mail/Views/mailbox/inbox.ascx
~/Areas/Mail/Views/Shared/inbox.aspx
~/Areas/Mail/Views/Shared/inbox.ascx
~/Views/mailbox/inbox.aspx
~/Views/mailbox/inbox.ascx
~/Views/Shared/inbox.aspx
~/Views/Shared/inbox.ascx
~/Areas/Mail/Views/mailbox/inbox.cshtml
~/Areas/Mail/Views/mailbox/inbox.vbhtml
~/Areas/Mail/Views/Shared/inbox.cshtml
~/Areas/Mail/Views/Shared/inbox.vbhtml
~/Views/mailbox/inbox.cshtml
~/Views/mailbox/inbox.vbhtml
~/Views/Shared/inbox.cshtml
~/Views/Shared/inbox.vbhtml
I tested below urls for inbox page, but no one was successful
- http://localhost:port/Mail
- http://localhost:port/Mail/Mailbox
- http://localhost:port/Mail/Mailbox/inbox
How can i fix it? Thanks