VS2013 MVC - 显示名称在某些字段上不起作用

VS2013 MVC - Display name not working on some fields

刚开始使用 MVC。

我有一个模型并为持久数据注释创建了一个元数据 class。有些有效,有些无效。

正如您从屏幕截图中看到的,JobNo displayName 不起作用,但 VersionRef 起作用。想不通为什么。

有人有什么想法吗?主要区别在于来自相关 table

的 Jobno

经过更多调查,似乎出于某种原因,脚手架 .cshtml 包含来自相关 table 的任何字段的文字字符串。

<div class="form-horizontal">
    <h4>Job</h4>
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    <div class="form-group">
        @Html.LabelFor(model => model.JobNo, "JobNo", htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.DropDownList("JobNo", null, htmlAttributes: new { @class = "form-control" })
            @Html.ValidationMessageFor(model => model.JobNo, "", new { @class = "text-danger" })
        </div>
    </div>

这有什么理由吗?

此致

标记

你试过这个吗? [DisplayAttribute(名称="Full Name")] 或 [DisplayName("Full Name")]

你可以检查这个link:Example

据此:

https://msdn.microsoft.com/en-us/library/hh833698%28v=vs.118%29.aspx

您正在使用带有 labelText 参数的 LabelFor 的重载。

public static MvcHtmlString LabelFor<TModel, TValue>(
    this HtmlHelper<TModel> html,
    Expression<Func<TModel, TValue>> expression,
    string labelText,
    IDictionary<string, Object> htmlAttributes)

labelText Type: System.String The label text to display.

考虑使用:

@Html.LabelFor(model => model.JobNo, 
    new { @class = "control-label col-md-2" })

有关更多重载,请参阅 https://msdn.microsoft.com/en-us/library/system.web.mvc.html.labelextensions.labelfor%28v=vs.118%29.aspx

经过更多调查,似乎出于某种原因,脚手架 .cshtml 包含相关表中任何字段的文字字符串。