“@Model”, “@Viewbag” and “@Url” “does not exist in

2020-07-02 22:08发布

I've created an MVC3 application in Visual Studio 10. When editing views the "@Model", "@Viewbag" and "@Url" all appear valid.

I recently installed Visual Studio 11 Beta and when editing (or creating) views I get "x does not exist in current context" error for the above keywords and obviously no intelli-sense.

I have since installed Visual Studio 2012 RC hoping it was just a Visual Studio 11 Beta issue.... it wasn't. Since running it in Visual Studio 2012 RC I've noticed the "@Html" key word exists however however the the intelli-sense list is limited - anything relating to the Model (eg "@Html.EditorFor()") and anything in the "Render" family is missing.

If I run the project everything is fine.

Now if I create a new project within Visual Studio 11 Beta/2012 RC all keywords are recognised.

Is there something I need to edit in my project files to get it to work correctly?

Edit - More of an answer, copied from my comment below For people upgrading to VS 2015, it doesn't support MVC 4 you need to upgrade the project to MVC5. See - http://www.asp.net/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

3条回答
倾城 Initia
2楼-- · 2020-07-02 22:38

For anyone that hits this page through searching, I was able to resolve this myself by following the guide on this page, line by line, until I could rebuild the project. Once I rebuilt and reloaded the project, all the intellisense came back for me.

Here is the link: http://www.asp.net/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

查看更多
▲ chillily
3楼-- · 2020-07-02 22:54

Add the following setting to your MAIN web.config file's appSettings section:

<add key="webpages:Version" value="1.0.0.0"/>

From Connect: http://connect.microsoft.com/VisualStudio/feedback/details/732597/visual-studio-11-beta-razor-intellisense-not-working

查看更多
劫难
4楼-- · 2020-07-02 22:57

An update for vs2015;

Look for this element in your MAIN web.config

  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>

and place the "newVersion" parameter in your webPages:version

ie

<add key="webpages:Version" value="3.0.0.0" />
查看更多
登录 后发表回答