Can't Add View from Controller in VS 2015 : “There was an error running the selected code generator”

前端 未结 21 2073
独厮守ぢ
独厮守ぢ 2020-11-27 18:34

I\'m following a video tutorial where I\'m required to create an empty ASP.NET Web Application with MVC, using Visual Studio 2015, bei

相关标签:
21条回答
  • 2020-11-27 19:31

    A simple VS restart worked for me. I just closed VS and restarted.

    0 讨论(0)
  • 2020-11-27 19:32

    Try clearing the ComponentModelCache, the cache will rebuild next time VS is launched.

    1. Close Visual Studio
    2. Delete everything in this folder C:\Users\ [your users name] \AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache
    3. Restart Visual Studio

    14.0 is for visual studio 2015. This will work for other versions also.

    0 讨论(0)
  • 2020-11-27 19:36

    Deleting the .vs folder inside the solution directory worked for me.

    0 讨论(0)
  • 2020-11-27 19:36

    I know this is a really old thread, but I came across it whilst working on my issue. Mine was caused because I had renamed one of my Model classes. Even though the app built and ran fine, when I tried to add a new controller I got the same error. For me, I just deleted the class I had renamed, added it back in and all was fine.

    0 讨论(0)
  • 2020-11-27 19:37

    In ASP.NET Core check if you have the Microsoft.VisualStudio.Web.CodeGeneration.Tools nuget package and it corresponds to your project version.

    0 讨论(0)
  • 2020-11-27 19:39

    Follow these steps to add a view in a different way than the typical way:

    • 1) Open Visual studio.
    • 2) Create/open your project.
    • 3) Go to Solution Explorer.
    • 4) Right click on the target folder.
    • 5) From the list, choose Add.
    • 6) From the child list, choose MVC View Page (Razor) or MVC View Page with layout (Razor).
    • 7) If you select the second choice from the previous step, you should choose a layout page for your view from the pop up window.
    • 8) That's it!

    If you cannot open the view that you are created, simply right click on the view file, choose Open with, and select HTML (web forms) editor then okay.

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