Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The view 'Index' or its master was not found.

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.

like image 638
Fitzchak Yitzchaki Avatar asked Feb 15 '10 22:02

Fitzchak Yitzchaki


3 Answers

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");
like image 85
Shannon Deminick Avatar answered Nov 18 '22 08:11

Shannon Deminick


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).

  1. Corresponding Controllers and View folders name have the same names.
  2. Corresponding Controller methods & Views pages should same have the same names.
  3. If your method name is different than view name, return view("viewName") in the method.
like image 29
Sai Sherlekar Avatar answered Nov 18 '22 08:11

Sai Sherlekar


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. enter image description here

2. Click Add View.. and give appropriate name.In this example name should be Index.

enter image description here

Then it will add correct View by creating with relevant folder structure.

like image 14
Elshan Avatar answered Nov 18 '22 09:11

Elshan