The view 'Index' or its master was not found.
Solution 1
The problem was that I used MvcRoute.MappUrl
from MvcContrib
to route the context.Routes
.
It seems that MvcContrib
routing mapper was uncomfortable with area routing.
Solution 2
What you need to do is set a token to your area name:
for instance:
context.MapRoute(
"SomeArea_default",
"SomeArea/{controller}/{action}/{id}",
new { controller = "SomeController", action = "Index", id = UrlParameter.Optional }
).DataTokens.Add("area", "YOURAREANAME");
Solution 3
This error was raised because your Controller method name is not same as the View's name.
If you right click on your controller method and select Go To View (Ctrl+M,Ctrl+G), it will either open a View (success) or complain that it couldn't find one (what you're seeing).
- Corresponding Controllers and View folders name have the same names.
- Corresponding Controller methods & Views pages should same have the same names.
- If your method name is different than view name,
return view("viewName")
in the method.
Solution 4
Global.asax file contain the URL Route. Default URL route like this.
"{controller}/{action}/{id}"
So,Try this.
1. Right click your controller method as below.
Example: let say we call Index()
method.Right click on it.
2. Click Add View.. and give appropriate name.In this example name should be Index.
Then it will add correct View by creating with relevant folder structure.
Solution 5
Check the generated code at MyAreaAreaRegistration.cs and make sure that the controller parameter is set to your default controller, otherwise the controller will be called bot for some reason ASP.NET MVC won't search for the views at the area folder
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"SomeArea_default",
"SomeArea/{controller}/{action}/{id}",
new { controller = "SomeController", action = "Index", id = UrlParameter.Optional }
);
}
Fitzchak Yitzchaki
Updated on July 08, 2022Comments
-
Fitzchak Yitzchaki almost 2 years
The view 'Index' or its master was not found. The following locations were searched: ~/Views/ControllerName/Index.aspx ~/Views/ControllerName/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx
I got this error when using ASP.Net mvc area. The area controller action are invoked, but it seems to look for the view in the 'base' project views instead of in the area views folder.