2013-08-01 38 views
1

我無法在我的剃鬚刀應用程序中使用Html.Action或@ Url.Action,我在頁面頂部缺少指令或程序集。我想將鏈接添加到其持有編輯網格和刪除按鈕,將其有人能幫助我@ Url.Action或Html.Action在Razor中缺少指令或程序集

var columns = new List<WebGridColumn>(); 
columns.Add(new WebGridColumn{ ColumnName = "name", Header = "Name"}); 

var grid = new WebGrid(db.Query("SELECT * FROM d_heirachy"));  
@grid.GetHtml(
tableStyle:"MyStyle", 
headerStyle:"ColumnHeader", 
alternatingRowStyle:"alternate-row", 
columns: columns);   

這是我的webconfig

<configuration> 
<configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
</configSections> 
<system.web> 
    <compilation debug="true" targetFramework="4.5"> 
    <assemblies>   
     <add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
    </assemblies> 
    <buildProviders> 
     <add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider" /> 
    </buildProviders> 
    </compilation> 
    <httpRuntime targetFramework="4.5" /> 
</system.web> 
<connectionStrings> 
    <add name="StarterSite" connectionString="Data Source=|DataDirectory|\StarterSite.sdf" providerName="System.Data.SqlServerCe.4.0" /> 
    <add name="StoreEntities" connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlServerCe.4.0;provider connection string=&quot;data source=|DataDirectory|\StarterSite.sdf&quot;" providerName="System.Data.EntityClient" /> 
</connectionStrings> 
<system.data> 
    <DbProviderFactories> 
    <remove invariant="System.Data.SqlServerCe.4.0" /> 
    <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" /> 
    </DbProviderFactories> 
</system.data> 
<entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
</entityFramework> 

回答

1

聽起來像是你要麼您的視圖目錄中缺少web.config文件,或者您缺少System.Web.WebPages.Razor部分,該部分定義了每個視圖中要包含的命名空間(默認情況下)。

您的視圖配置應該有上述節點定義名稱空間節點,其中包括像System.Web.Mvc。例如,我的~/Views/web.config有內<configuration>以下部分:

<system.web.webPages.razor> 
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.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="System.Web.Optimization" /> 
     </namespaces> 
    </pages> 
</system.web.webPages.razor> 
+0

我已經更新我的職務與我的webconfig – ONYX

+0

@KDM錯誤配置。你應該有兩個:一個在你的應用程序文件夾中,另一個在你的視圖目錄中。我正在談論後者。 –

0

當你創建一個新的MVC應用程序的項目,你可能沒有注意到。在「視圖」目錄中有另一個web.config,它只適用於它的目錄。

another web.config for "Views"

如果手動創建ASP.NET Web應用程序或網站,您必須創建此爲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=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
     <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> 
     <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.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=4.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" /> 
     </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=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" 
     pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" 
     userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
     <controls> 
     <add assembly="System.Web.Mvc, Version=4.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> 
</configuration> 
+0

我創建了一個Razor(V2)應用程序網站,在那個應用程序中我沒有看到一個視圖目錄。現在發生什麼我無法使用Html.ActionLink或@ Url.Action我該怎麼辦 – ONYX

+0

如何使用VS2010創建網站 – ONYX

+0

的模型文件>新建項目...>已安裝的模板> visual c#> Web(選擇.NET Framework 4)>「ASP.NET MVC Web應用程序」 – aifarfa

0

試試這個

<runtime> 
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    <dependentAssembly> 
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" /> 
    </dependentAssembly>  
</assemblyBinding> 
</runtime> 

你缺少包括System.Web.MvcWeb.config

相關問題