Question

Is there a way to use the [DisplayName("My descriptive Name")] in headers and just the column name when I display data?

(Without having to type each one in?) - (I used MVC scaffolding to create the edit page)

<p>
    @Html.ActionLink("Create New", "CreateTask")
</p>
<table>
    <tr>
    <th>
        @Html.DisplayNameFor(model => model.Name)
    </th>
    </tr>
<td>
@foreach (var item in Model) {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.Name)
    </td>
</tr>
}
</table>
Was it helpful?

Solution

Add properties Display in Model like this

[Display(Name = "Your Custom Name")]
 public string Name { get; set; }

And in Razor View, use

@Html.LabelFor(model=>model.Name)

Hope this help you DAN.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top