Asp.net MVC 5无法在类库项目

时间:2017-02-18 21:57:41

标签: razor asp.net-mvc-5 html-helper embedded-resource portable-class-library

使用Asp.Net MVC 5制作插件架构应用程序,因此我创建了一个包含一些控制器和一些嵌入式Razor视图的类库项目。一切正常我做了一些引用下面的几个`System.Web.Mvc / System.Web.Optimazations / System.Web.Razor / System.Web.WebPages / System.Web.WebPages.Razor / System.Web.helpers。< / p>

我添加了一个web.config文件,它包含的内容为:

<?xml version="1.0"?>

<configuration>
  <configSections>
    <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>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.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.Optimization"/>
        <add namespace="System.Web.Routing" />
        <add namespace="Plugin_1" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

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

  <system.web>
    <compilation debug="true" targetFramework="4.5.2" >


    </compilation>

    <httpRuntime targetFramework="4.5.2" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
        <add namespace="Plugin_1" />
        <add namespace="Kendo.Mvc.UI"/>
      </namespaces>
    </pages>
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
    </httpModules>
  </system.web>

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

我可以使用@model关键字等,但我不能使用像@ Html.ActionLink()等的html助手,@ HTML不被vs 2015认可! 任何人都可以帮助我,我在StackOF上看到了一些类似的问题,但它没有帮助。谢谢。

2 个答案:

答案 0 :(得分:1)

要使Intellisense显示ASP.NET MVC特定的属性,您需要将类库的输出路径更改为var rootRef = firebase.database().ref().child("Balkar/Employees"); rootRef.on('child_added', snap => { var id = snap.child("ID").val(); var key = snap.key; var name = snap.child("Name").val(); var email = snap.child("Email").val(); var btn = "<button key='"+ key +"' class='removeEmployee mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent'>Remove</button>"; $("#table_body").append("<tr id='"+key+"'><td>" + id + "</td><td>" + name + "</td> <td>" + email + "</td><td>" + btn + "</td></tr>"); }); // now this click handler can be (should be) moved outside 'child_added' callback $('#table_body').on('click', ".removeEmployee", function(){ // note: using 'removeElement' as class, not as id var key = $(this).attr('key'); var itemToRemove = rootRef.child(key); itemToRemove.remove() .then(function() { // removed from Firebase DB console.log("Remove succeeded.") }) .catch(function(error) { console.log("Remove failed: " + error.message) }); }); // keeping this separate so that even if the item is removed by any other means (e.g.- directly from server console) this UI will remain in sync rootRef.on('child_removed', function(snap) { var key = snap.key; $('#'+key).remove(); });

右键点击项目 - &gt;属性 - &gt;构建 - &gt;将输出路径更改为“bin /”

现在,如果您在类库中打开Razor文件,您将获得bin等内容的智能感知。

答案 1 :(得分:0)

您需要在项目和Web配置中添加razor引用