简体   繁体   中英

VS2013 MVC - Display name not working on some fields

Just getting started with MVC.

I have a model and have created a metadata class for persistent data annotations. Some of them work and some don't.

屏幕截图

As you can see from the screen shot, the JobNo displayName isn't working, but the VersionRef is. Can't figure out why.

Anyone got any ideas? main difference is that Jobno from a related table

After some more investigation, it seems that for some reason the scaffolded .cshtml contains a literal string for any fields that from related tables.

<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>

Is there a raeson for this?

Regards

mark

Have you tried this? [DisplayAttribute(Name="Full Name")] OR [DisplayName("Full Name")]

You can check this link: Example

According to this:

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

You are using the overload of LabelFor with the labelText parameter.

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.

Consider to use:

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

See https://msdn.microsoft.com/en-us/library/system.web.mvc.html.labelextensions.labelfor%28v=vs.118%29.aspx for more overloads.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM