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

后端 未结 17 2205
逝去的感伤
逝去的感伤 2020-12-15 14:42
The view \'Index\' or its master was not found. The following locations were searched:
~/Views/ControllerName/Index.aspx
~/Views/ControllerName/Index.ascx
~/Views/Sh         


        
相关标签:
17条回答
  • 2020-12-15 15:21

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

    ViewEngines.Engines.Add(new RazorViewEngine());
    
    0 讨论(0)
  • 2020-12-15 15:22

    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"
            };
    
    0 讨论(0)
  • 2020-12-15 15:25

    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.
    0 讨论(0)
  • 2020-12-15 15:25

    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 }
            );
        }
    
    0 讨论(0)
  • 2020-12-15 15:25

    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.

    0 讨论(0)
  • 2020-12-15 15:25

    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
    
    0 讨论(0)
提交回复
热议问题