views:

48

answers:

2

Hi!

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?

A: 

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.

Matthew Abbott
+2  A: 

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

OJ
stil getting 404 error. What should I do for controllers?
Kaan
changing the namespace solved :) thanks
Kaan
Happy to help :)
OJ