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

asp.net Mvcasp.net Mvc-Routingasp.net Mvc-Areas

asp.net Mvc Problem Overview


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.

asp.net Mvc Solutions


Solution 1 - asp.net Mvc

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 2 - asp.net Mvc

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.

Solution 3 - asp.net Mvc

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.

Solution 4 - asp.net Mvc

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 }
        );
    }

Solution 5 - asp.net Mvc

Where this error only occurs when deployed to a web server then the issue could be because the views are not being deployed correctly.

An example of how this can happen is if the build action for the views is set to None rather than Content.

A way to check that the views are deployed correctly is to navigate to the physical path for the site on the web server and confirm that the views are present.

Solution 6 - asp.net Mvc

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 7 - asp.net Mvc

You most likely did not create your own view engine.
The default view engine looks for the views in ~/Views/[Controller]/ and ~/Views/Shared/.

You need to create your own view engine to make sure the views are searched in area views folder.

Take a look this post by Phil Haack.

Solution 8 - asp.net Mvc

I had this problem today with a simple out of the box VS 2013 MVC 5 project deployed manually to my local instance of IIS on Windows 8. It turned out that the App Pool being used did not have the proper access to the application (folders, etc.). After resetting my App Pool identity, it worked fine.

Solution 9 - asp.net Mvc

  1. right click in index() method from your controller
  2. then click on goto view

if this action open index.cshtml?

Your problem is the IIS pool is not have permission to access the physical path of the view.

you can test it by giving permission. for example :- go to c:\inetpub\wwwroot\yourweb then right click on yourweb folder -> property ->security and add group name everyone and allow full control to your site . hope this fix your problem.

Solution 10 - asp.net Mvc

It´s still a problem on the Final release.. .when you create the Area from context menu/Add/Area, visual studio dont put the Controller inside de last argument of the MapRoute method. You need to take care of it, and in my case, I have to put it manually every time I create a new Area.

Solution 11 - asp.net Mvc

You can get this error even with all the correct MapRoutes in your area registration. Try adding this line to your controller action:

If Not ControllerContext.RouteData.DataTokens.ContainsKey("area") Then
    ControllerContext.RouteData.DataTokens.Add("area", "MyAreaName")
End If

Solution 12 - asp.net Mvc

If You can get this error even with all the correct MapRoutes in your area registration and all other basic configurations are fine.

This is the situation:

I have used below mentioned code from Jquery file to post back data and then load a view from controller action method.

$.post("/Customers/ReturnRetailOnlySales", {petKey: '<%: Model.PetKey %>'}); 

Above jQuery code I didn't mentioned success callback function. What was happened there is after finishing a post back scenario on action method, without routing to my expected view it came back to Jquery side and gave view not found error as above.

Then I gave a solution like below and its working without any problem.

 $.post("/Customers/ReturnRetailOnlySales", {petKey: '<%: Model.PetKey %>'},
      function (data) {
 var url = Sys.Url.route('PetDetail', { action: "ReturnRetailOnlySalesItems", controller: "Customers",petKey: '<%: Model.PetKey %>'});
 window.location = url;});   

Note: I sent my request inside the success callback function to my expected views action method.Then view engine found a relevant area's view file and load correctly.

Solution 13 - asp.net Mvc

I have had this problem too; I noticed that I missed to include the view page inside the folder that's name is same with the controller.

Controller: adminController View->Admin->view1.cshtml

(It was View->view1.cshtml)(there was no folder: Admin)

Solution 14 - asp.net Mvc

This error can also surface if your MSI installer failed to actually deploy the file.

In my case this happened because I converted the .aspx files to .cshtml files and visual studio thought these were brand new files and set the build action to none instead of content.

Solution 15 - asp.net Mvc

I got the same problem in here, and guess what.... looking at the csproj's xml' structure, I noticed the Content node (inside ItemGroup node) was as "none"... not sure why but that was the reason I was getting the same error, just edited that to "Content" as the others, and it's working.

Hope that helps

Solution 16 - asp.net Mvc

Add the following code in the Application_Start() method inside your project:

ViewEngines.Engines.Add(new RazorViewEngine());

Solution 17 - asp.net Mvc

I added viewlocationformat to RazorViewEngine and worked for me.

ViewLocationFormats = new[] {
            "~/Views/{1}/{0}.cshtml",
            "~/Views/Shared/{0}.cshtml",
            "~/Areas/Admin/Views/{1}/{0}.cshtml",
            "~/Areas/Admin/Views/Shared/{0}.cshtml"
        };

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFitzchak YitzchakiView Question on Stackoverflow
Solution 1 - asp.net MvcShannon DeminickView Answer on Stackoverflow
Solution 2 - asp.net MvcSai SherlekarView Answer on Stackoverflow
Solution 3 - asp.net MvcElshanView Answer on Stackoverflow
Solution 4 - asp.net MvcRaphaelView Answer on Stackoverflow
Solution 5 - asp.net MvcScott MunroView Answer on Stackoverflow
Solution 6 - asp.net MvcFitzchak YitzchakiView Answer on Stackoverflow
Solution 7 - asp.net MvcÇağdaş TekinView Answer on Stackoverflow
Solution 8 - asp.net MvcGreg GraterView Answer on Stackoverflow
Solution 9 - asp.net MvcBeruk BerhaneView Answer on Stackoverflow
Solution 10 - asp.net MvcMichael CastroView Answer on Stackoverflow
Solution 11 - asp.net MvcMindstorm InteractiveView Answer on Stackoverflow
Solution 12 - asp.net MvcSampathView Answer on Stackoverflow
Solution 13 - asp.net MvcfreewillView Answer on Stackoverflow
Solution 14 - asp.net MvcmicahhooverView Answer on Stackoverflow
Solution 15 - asp.net MvcMGEView Answer on Stackoverflow
Solution 16 - asp.net MvcSagar PithadiyaView Answer on Stackoverflow
Solution 17 - asp.net Mvcnazlı balatlıoğluView Answer on Stackoverflow