2012-03-14 77 views
2

使用ASP.NET MVC4測試版中的移動應用程序播放,使用的效果非常好,但是在顯示模式方面存在問題article。也就是說,我嘗試使用ASP.NET MVC4移動版:CS0103:當前上下文中不存在名稱'DisplayModes'

@{ 
    ViewBag.Title = "ASP.NET Articles"; 
    DisplayModes.RequireConsistentDisplayMode = true;  
} 

我_ViewStart.cshtml內,但得到的complition錯誤:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'DisplayModes' does not exist in the current context

任何一個人看到呢?

+0

我想補充一點,DisplayModes類是不適用於我。 – 2012-03-14 09:39:26

回答

3

鏈接的文章是從2011年9月12日,所以他們似乎改變了API。

試試這個(工作在MVC4測試版):

@{ 
    ViewBag.Title = "ASP.NET Articles"; 
    DisplayModeProvider.Instance.RequireConsistentDisplayMode = true; 
} 
+0

偉大的答案,謝謝! – 2012-03-14 09:50:57

+1

您可能最好在Global.asax.cs的Application_Start中將'DisplayModeProvider.Instance.RequireConsistentDisplayMode = true'設置爲一次,而不是將其設置在將爲每個頁面請求運行的_ViewStart.cshtml中。 – 2012-10-16 02:34:25

相關問題