拋開visual studio,純手工建立asp.net mvc遇到的問題

來源:互聯網
上載者:User

標籤:white   entry   精簡   cti   code   perm   mode   文本編輯   size   

脫離Visual Studio,只用文字編輯器、.NET Framework、IIS Express建立ASP.NET MVC應用時,需要精簡~/View目錄下web.config檔案內容,之前建立的asp.net mvc hellow world應用一切正常,在清理web.config檔案後,出現如下錯誤:

The view must derive from WebViewPage, or WebViewPage<TModel>. (The view at ‘~/Views/home/index.cshtml’ must derive from WebViewPage, or WebViewPage<TModel>.)

詳細的解決方案,請參考這裡:https://blogs.msdn.microsoft.com/gaurav/2014/01/14/the-view-must-derive-from-webviewpage-or-webviewpagetmodel-the-view-at-viewshomeindex-cshtml-must-derive-from-webviewpage-or-webviewpagetmodel/

Web應用根目錄下的Web.config檔案可以沒有,只要有Global.asax檔案就行,但為瞭解析MVC中cshtml格式檔案,一種是使每個頁面繼承自“@inherits System.Web.Mvc.WebViewPage”,_ViewStart.cshtml檔案繼承自@inherits System.Web.WebPages.StartPage;這樣每個頁面都寫也挺麻煩,第二種方法就是增加~/View目錄下的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>    <pages pageBaseType="System.Web.Mvc.WebViewPage" ></pages>  </system.web.webPages.razor></configuration>

備忘:上文中建立的最簡但的ASP.NET MVC應用helloworld,只在view中列印一行文本,以驗證MVC中Controller和View運行是否正確。

拋開visual studio,純手工建立asp.net mvc遇到的問題

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.