2012-03-14 67 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

相关问题