The view 'Index' or its master was not fou

2019-01-23 10:32发布

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.

15条回答
成全新的幸福
2楼-- · 2019-01-23 10:42

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.

查看更多
男人必须洒脱
3楼-- · 2019-01-23 10:46

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.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-01-23 10:47

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 }
        );
    }
查看更多
来,给爷笑一个
5楼-- · 2019-01-23 10:49

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.

查看更多
来,给爷笑一个
6楼-- · 2019-01-23 10:50

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");
查看更多
狗以群分
7楼-- · 2019-01-23 10:50

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.

查看更多
登录 后发表回答