MVC Razor 视图 Intellisense 在 VS 2013/2015/2017 中被破坏 [英] MVC Razor view Intellisense broken in VS 2013/2015/2017

查看:15
本文介绍了MVC Razor 视图 Intellisense 在 VS 2013/2015/2017 中被破坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 VS2010 编写的现有项目,在 VS2010 中加载时可以完美运行.

I have an existing project written in VS2010 which when loaded in VS2010 works perfectly.

当我在 VS2013 中加载同一个项目时,MVC Razor 视图包含很多错误,就好像视图文件夹中缺少配置文件一样.

When I load this same project in VS2013 the MVC Razor views contain lots of errors as if the config file is missing from the views folder.

它似乎没有使用根目录和视图文件夹中的配置文件正确加载 Razor 编辑器,而是给了我类似的错误......

It appears to have not loaded the Razor editor correctly using the config files from both the root and the views folder and instead gives me errors like ...

The name 'model' does not exist in the current context

和...

'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'LabelFor' 
and no extension method 'LabelFor' accepting a first argument of type 
'System.Web.WebPages.Html.HtmlHelper' could be found 
(are you missing a using directive or an assembly reference?)

...

知道什么会导致这种情况吗?

Any idea what would cause this?

根据要求配置文件....

Config files as requested ....

来自主 web.config 文件(不是全部,因为它太大而无法发布)

From main web.config file (not all of it as it's way too big to post)

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Ninject" culture="neutral" publicKeyToken="c7192dc5380945e7" />
            <bindingRedirect newVersion="3.0.0.0" oldVersion="0.0.0.0-3.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Validation" culture="neutral" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect newVersion="5.0.505.0" oldVersion="0.0.0.0-5.0.505.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Web" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.2.0.0" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>

~/Views/"中的配置文件...

Config file in "~/Views/" ...

<?xml version="1.0"?>  
<configuration>
    <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
            <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
        </sectionGroup>
    </configSections>

    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
            <namespaces>
                <add namespace="System.Web.Mvc" />
                <add namespace="System.Web.Mvc.Ajax" />
                <add namespace="System.Web.Mvc.Html" />
                <add namespace="System.Web.Routing" />
                <add namespace="Emedia.Common.Mvc.Views.Helpers"/>
                <add namespace="Emedia.Common.Mvc.Views.Extensions"/>
        <add namespace="Emedia.Common.Utilities"/>
        <add namespace="Emedia.Common.Utilities.Extensions"/> 
        <add namespace="Emedia.Common.Mvc.Controllers.Helpers"/>
                <add namespace="Emedia.Resources.Service"/>
        <add namespace="Emedia.Subscriber.Controllers"/>
        <add namespace="Emedia.Subscriber.Controllers.ViewModels"/>
            </namespaces>
        </pages>
    </system.web.webPages.razor>

    <appSettings>
        <add key="webpages:Enabled" value="false" />
    </appSettings>

    <system.web>
        <httpHandlers>
            <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
        </httpHandlers>
        <pages
            validateRequest="false"
            pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <controls>
                <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
        </controls>
    </pages>
</system.web>

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />

    <handlers>
        <remove name="BlockViewHandler"/>
        <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
</system.webServer>

推荐答案

我考虑过编辑 @ChrisMoschini 的帖子,但认为它已经足够不同了.我的问题是我启动了一个新的 MVC5 应用程序,并从我想用作模板/起点的旧 MVC3 项目中盲目地复制了太多的 web.config 设置.这样做导致我在我的 web.config 中引用了一些无效的版本.

I considered editing @ChrisMoschini's post, but thought it was different enough. My issue was that I started a new MVC5 application, and blindly copied over too many web.config settings from an old MVC3 project I wanted to use as a template/starting point. Doing this caused me to have some invalid versions referenced in my web.config.

为了解决这个问题,我创建了另一个新的 MVC5 项目,并确保我的坏项目中的以下配置值与 vanilla、未修改的 MVC5 应用程序相匹配.再次强调,不要盲目复制这些版本号.只需确保它们与您尝试开始工作的版本的 vanilla MVC 应用程序相匹配

To fix, I created another new MVC5 project and made sure the following config values in my bad project matched the vanilla, unmodified MVC5 app. Again, do not blindly copy these version numbers. Just make sure they match a vanilla MVC app of the version that you're trying to get to work

在根 web.config 中:

<appSettings>
    ...
    <add key="webpages:Version" value="3.0.0.0"/> 
    ...
</appSettings>
<system.web>
    ...
    <compilation debug="true" targetFramework="4.5.1"/>
    <httpRuntime targetFramework="4.5.1"/>
    ...
</system.web>

ViewsWeb.config 中:

<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    ...
    <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    ...
</sectionGroup>


<system.web.webPages.razor>
  ...
  <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  ...
</system.web.webPages.razor>

这篇关于MVC Razor 视图 Intellisense 在 VS 2013/2015/2017 中被破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆