zoukankan      html  css  js  c++  java
  • ASP.NET MVC 3.0 视图在类库项目中无法智能提示解决方法

    由于某种架构的需要,许多视图(.cshtml)被分布到不同的类库项目中,在项目编译时通过post-build复制到启动项的指定目录。部分开发人员在一些项目中修改视图时出现无法智能提示。Views文件夹下有Web.config,当打开某个.cshtml文件出现提示:“ASP.NET runtime error: There is no build provider registered for the extension '.cshtml'. You can register one in the <compilation><buildProviders> section in the machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.”。

    在项目根目录中添加Web.config,并复制如下内容:

    <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" />
          </namespaces>
        </pages>
      </system.web.webPages.razor>
    
      <system.web>
        <compilation targetFramework="4.0">
          <assemblies>
            <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          </assemblies>
        </compilation>
      </system.web>
    </configuration>
  • 相关阅读:
    使用 ASP.NET Core 创建 Web API
    C# 请求接口返回中文乱码→???
    无法从命令行或调试器启动服务,必须首先安装Windows服务(使用installutil.exe),然后用ServerExplorer、Windows服务器管理工具或NET START命令启动它
    制作和引用自定义图标库
    asp.net core 3.1 解决跨域的问题
    看自己以前写的代码
    图解SQL Server 数据库定时自动备份
    码云修改登录密码后终端连不上的问题
    C#中string.format用法详解
    C#高级编程之泛型详解
  • 原文地址:https://www.cnblogs.com/junchu25/p/2697617.html
Copyright © 2011-2022 走看看