MVC4.0,並完美結合Razor引擎

來源:互聯網
上載者:User

標籤:ase   put   ajax   forms   ros   parse   ges   miss   pre   

本文主要解決“當前上下文不存在ViewBag”的問題,

在View視圖實際使用過程中,如果引用不正確會提示“當前上下文不存在ViewBag”,首先需要引入“Microsoft.CSharp”類庫

然後修改web.config,主要是添加“configSections”和“system.web.webPages.razor”區段

<?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.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>      <!--         Enabling request validation in view pages would cause validation to occur         after the input has already been processed by the controller. By default         MVC performs request validation before a controller processes the input.         To change this behavior apply the ValidateInputAttribute to a         controller or action.     -->     <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>

 

MVC4.0,並完美結合Razor引擎

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.