Kaan
Kaan

Reputation: 896

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?

Upvotes: 1

Views: 533

Answers (2)

OJ.
OJ.

Reputation: 29401

Rather than creating subfolders like that under Views, take a look at Areas. This may better help solve your problem.

Upvotes: 3

Matthew Abbott
Matthew Abbott

Reputation: 61579

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.

Upvotes: 0

Related Questions