The view 'Index' or its master was not found

前端 未结 9 1386
南方客
南方客 2020-12-03 16:03

I\'m new to the C# MVC project type and when I created an empty C# MVC project, I noticed the following error:

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


        
相关标签:
9条回答
  • 2020-12-03 16:13

    MVC looks for views (like Index) under the views folder but they also have to be under a folder named after their controller (with a few exceptions like partials).

    So this is the structure you want to follow in your project

    Controllers (folder)
        HomeController (.cs)
        AccountController (.cs)
    
    Views (folder)
        Home (folder)
            Index (.cshtml)
        Account (folder)
            Index (.cshtml)
    
    0 讨论(0)
  • 2020-12-03 16:15

    A useful diagnostic step is to right click inside the Controller's Action, choose "Go To View".

    If Visual Studio can find the view, then it's probably in the right folder, so re-check your URL. For example, if using an Area then the area name should be in the URL:

    /Area/Controller/Action
    
    0 讨论(0)
  • 2020-12-03 16:17

    I know this is an old post but I ran into this same situation running on Ubuuntu 16.04 and Mono 4.2.1 and none of this helped. I started digging into other things and after a week I found out that for some reason Microsoft.Web.WebPages.OAuth.dll was causing this error. after deleting that dll and removing all refrenses to it (I'm not using the open auth anyway) everything immediately started working even using simple membership with MySQL. So I wanted to post this here in case someone else runs into this same situation on Mono and Linux because this comes up in google.

    0 讨论(0)
  • 2020-12-03 16:21

    When a view is returned, it expects that an associated .cshtml file is in the same view folder structure as the controller layout for that area (if no areas are in use, then there is only 1 view folder and 1 controller folder). The controller name will be the folder name in the views folder, and the actionresult name will be the expected name of the .cshtml file.

    Luckily there is an easy way to remedy the situation where the view file is missing. Right click on Index for your action result, and then select Add View. Click okay, and it will create Index.cshtml for you inside of the correct folder. Now when you run the project, and navigate to Index, that is what you will see.

    0 讨论(0)
  • 2020-12-03 16:21

    You may have old/bad ASP.Net assemblies in your build.

    If you've made sure you have your Controller, namespace and View names all in the right place, there's a good chance your MVC/ASP Assembly is having problems working with the current Mono environment.

    If you've tried the tricks to copy all the .Net assemblies you can find and tag them into your bin, there's a good chance Mono or its configuration is not melding correctly - and you don't need to do that anymore. I had this problem when updating a machine to the latest Mono build. I wiped these assemblies from my bin, and NuGet'ed the latest assemblies in the Mono MVC Packages folder.

    First thing you'll see is:

    • Microsoft.AspNet.Mvc
    • Microsoft.AspNet.Infrastructure
    • Microsoft.AspNet.WebPages
    • Microsoft.AspNet.Razor

    This will resolve these problems.

    0 讨论(0)
  • 2020-12-03 16:22

    The MVC engine search for a view under Shared or under the folder that is named like the prefix of your controller class. So if you have ABCController you need to have your Index.cshtml view under the folder Views/ABC.

    PS : In your example you have a suffix to your controller name (ControllerName), I don't think it is a good practice, always name your controllers [Name]Controller

    0 讨论(0)
提交回复
热议问题