ASP.NET MVC - 404 Problem
I have a view folder structure:
- Views
- Admin
- Post
- New
and routing is defined with:
routes.MapRoute(
"Admin", // Route name
"Admin/{controller}/{action}/{id}", // URL with parameters
new { controller = "Admin", action = "Index", id = UrlParameter.Optional }
);
But, for ex: /Admin/Post/New gives 404 error. Because It doesn't go to Admin folder first.
Err: The view 'New' or its master was not found. The following locations were searched: ~/Views/Post/New.aspx ~/Views/Post/开发者_开发问答New.ascx ~/Views/Shared/New.aspx ~/Views/Shared/New.ascx
How I can define the folder?
Rather than creating subfolders like that under Views
, take a look at Areas. This may better help solve your problem.
You don't need to do that. The web.config file in the /Views folder prohibits any views being accessed directly. Users won't be able to visit www.yoursite.com/Views/___Admin.
I'd rename them back to /Admin, /Post, /New etc.
Otherwise, you need to create a new ViewEngine (you can extend the WebFormsViewEngine) to supply the additional paths.
精彩评论