Reputation: 2430
I am trying to create a new route... Here the code:
routes.MapRoute(
name: "Services",
url: "Administration/{controller}/{action}/{id}",
defaults: new { controller = "Services", action = "Index", id = UrlParameter.Optional });
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
Now when I click on an actionlik, it redirects me on the correct controller:
@Html.ActionLink("Services", "Index","Services")
Here the Index Action in the Services controller
public ActionResult Index()
{
return View(); //Here it is where I stop debug
}
I arrive in the action.. and now my custom route should redirect to my view. Correct? I let you see what I see when i stop debug:
How you can see everything seems is well valorized. But when I obtain following error:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Services/Index.aspx
~/Views/Services/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Services/Index.cshtml
~/Views/Services/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
It does not look the view inside Administration folder!! In this way it works instead:
return View("~/Views/Administration/Services/Index.cshtml");
Where is wrong?
Thank you
Upvotes: 0
Views: 67
Reputation: 118957
Looks like you don't quite understand routing, or that routing is not the same thing as view resolution. Changing the URL to access an action method doesn't make it search new folders for your views. So you need to do one of the following:
return View("~/Views/Administration/Services/Index.cshtml");
Personally I recommend option 1.
Upvotes: 1