Templates 自定义输出的显示

Templates 自定义输出的显示,templates,asp.net-mvc-5.2,displayfor,Templates,Asp.net Mvc 5.2,Displayfor,我正在稳步进步:) 因此,我获得了一个包含产品列表的奇妙网格 现在,对于布尔值显示了一个非常糟糕的复选框。 我宁愿选择“是/否”之类的。因此,我在谷歌上找到了这篇精彩的文章:。 问题是他显示的输出不是有条件的,所以我的代码 看起来像这样: @inherits System.Web.Mvc.WebViewPage<string> @if @Model == True { <span>Yes</span> } @else{ <span> No

我正在稳步进步:)
因此,我获得了一个包含产品列表的奇妙网格
现在,对于布尔值显示了一个非常糟糕的复选框。
我宁愿选择“是/否”之类的。因此,我在谷歌上找到了这篇精彩的文章:。
问题是他显示的输出不是有条件的,所以我的代码 看起来像这样:

@inherits System.Web.Mvc.WebViewPage<string>
@if @Model == True
{
  <span>Yes</span>
}
@else{
  <span> No </span>
}
@继承System.Web.Mvc.WebViewPage
@如果@Model==True
{
对
}
@否则{
不
}
但是VS 2013的一切都是曲折的,这通常是一个坏兆头
当我尝试运行它时,我看到了复选框。嘿。。。要学的东西很多…
无论如何,我注意到了一个与我类似的问题,即为什么DisplayFor模板没有显示。我查看了OP的代码,发现他放了一个我的属性没有的数据类型属性(现在已经有了)。
然而,当我试图在我的模型中使用DataType属性时,VS再次变得扭曲——这是个坏兆头
当我试图编译时,天哪,一切都乱了套,我得到了6个编译错误(但这至少是一个进步,从简单地忽略所有内容开始!)。
错误如下:

Error   1   Expected a "{" but found a "@".  Block statements must be enclosed in "{" and "}".  You cannot use single-statement control-flow statements in CSHTML pages. For example, the following is not allowed:

@if(isLoggedIn)
    <p>Hello, @user</p>

Instead, wrap the contents of the block in "{}":

@if(isLoggedIn) {
    <p>Hello, @user</p>
}   c:\Users\Andrea\Documents\Visual Studio 2013\Projects\ARSoftLabs.it\ARSoftLabs.it\Views\Products\DisplayTemplates\ProductHasTrial.cshtml    2   4   ARSoftLabs.it
Error   2   ) expected  c:\Users\Andrea\Documents\Visual Studio 2013\Projects\ARSoftLabs.it\ARSoftLabs.it\Views\Products\DisplayTemplates\ProductHasTrial.cshtml    1   1   ARSoftLabs.it
Error   3   Syntax error, '(' expected  c:\Users\Andrea\Documents\Visual Studio 2013\Projects\ARSoftLabs.it\ARSoftLabs.it\Views\Products\DisplayTemplates\ProductHasTrial.cshtml    2   4   ARSoftLabs.it
Error   4   Invalid expression term 'else'  c:\Users\Andrea\Documents\Visual Studio 2013\Projects\ARSoftLabs.it\ARSoftLabs.it\Views\Products\DisplayTemplates\ProductHasTrial.cshtml    6   2   ARSoftLabs.it
Error   5   The type or namespace name 'DataTypeAttribute' could not be found (are you missing a using directive or an assembly reference?) c:\Users\Andrea\Documents\Visual Studio 2013\Projects\ARSoftLabs.it\ARSoftLabs.it\Models\Product.cs 20  10  ARSoftLabs.it
Error   6   The type or namespace name 'DataType' could not be found (are you missing a using directive or an assembly reference?)  c:\Users\Andrea\Documents\Visual Studio 2013\Projects\ARSoftLabs.it\ARSoftLabs.it\Models\Product.cs 20  10  ARSoftLabs.it
错误1应为“{”,但找到了“@”。块语句必须包含在“{”和“}”中。不能在CSHTML页面中使用单语句控制流语句。例如,不允许出现以下情况:
@如果(isLoggedIn)
你好,@user

而是将块的内容包装在“{}”中: @如果(isLoggedIn){ 你好,@user

}c:\Users\Andrea\Documents\Visual Studio 2013\Projects\ARSoftLabs.it\ARSoftLabs.it\Views\Products\DisplayTemplates\ProductHasTrial.cshtml 2 4 ARSoftLabs.it 错误2)应为c:\Users\Andrea\Documents\Visual Studio 2013\Projects\ARSoftLabs.it\ARSoftLabs.it\Views\Products\DisplayTemplates\ProductHasTrial.cshtml 1 1 1 ARSoftLabs.it 错误3语法错误,'('应为c:\Users\Andrea\Documents\Visual Studio 2013\Projects\ARSoftLabs.it\ARSoftLabs.it\Views\Products\DisplayTemplates\ProductHasTrial.cshtml 2 4 ARSoftLabs.it 错误4无效的表达式术语“else”c:\Users\Andrea\Documents\Visual Studio 2013\Projects\ARSoftLabs.it\ARSoftLabs.it\Views\Products\DisplayTemplates\ProductHasTrial.cshtml 6 2 ARSoftLabs.it 错误5找不到类型或命名空间名称“DataTypeAttribute”(是否缺少using指令或程序集引用?) 错误6找不到类型或命名空间名称“DataType”(是否缺少using指令或程序集引用?)
所以基本上我认为它告诉我我不知道jack关于Razor的事,这是非常坦率的事实。无论如何,之所以使用System.ComponentModel,是因为DisplayName属性的工作方式很有魅力,MSDN声称数据类型在同一个程序集中

想法?指针

谢谢


A

数据类型似乎驻留在一个外部包中。我曾尝试在nuGet中查找,但似乎找不到它。呵呵。我最终意识到,它在ComponentModel中是存在的,但在DataAnnotation中有一个更深的层次。我已经成功地构建了它,但现在我的新迁移不起作用了!天哪。