Jordan Axe
Jordan Axe

Reputation: 3923

Why does this not display the display name?

I'm trying to display the displaynames for the properties in my html in my ASP.NET MVC 4 application. However even though I've set the displaynames in the viewmodel the raw variable names still gets displayed instead.

The viewmodel:

public class Manage_ManagePasswordViewModel
{
    [Display(Name="Name")]
    public string name;
    [Display(Name = "SubID")]
    public string subId;
    [Display(Name = "Conversions")]
    public int conversions;
    [Display(Name = "Password")]
    public string password;
    public UserProfile owner;

    public Manage_ManagePasswordViewModel(ProtectedPassword pw)
    {
        name = pw.Name;
        subId = pw.SubId;
        conversions = pw.GetConversions();
        password = pw.Password;
        owner = pw.Owner;
    }
}

The cshtml file:

@model Areas.Admin.Models.ViewModels.Manage_ManagePasswordViewModel

<div class="editor-label">
    @Html.DisplayNameFor(m => m.name):
    @Html.DisplayTextFor(m => m.name)
</div>
<div class="editor-label">
    @Html.DisplayNameFor(m => m.password):
    @Html.DisplayTextFor(m => m.password)
</div>
<div class="editor-label">
    @Html.DisplayNameFor(m => m.subId):
    @Html.DisplayTextFor(m => m.subId)
</div>
<div class="editor-label">
    @Html.DisplayNameFor(m => m.conversions):
    @Html.DisplayTextFor(m => m.conversions)
</div>
<div class="editor-label">
    @Html.DisplayNameFor(m => m.owner.UserName):
    @Html.UserLink(Model.owner.UserName, Model.owner.UserId)
</div>

Upvotes: 4

Views: 2008

Answers (1)

Dmytro
Dmytro

Reputation: 1600

Use properties instead of fields, for ex.

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

Upvotes: 3

Related Questions