I have a model class similar to the following:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
[System.Runtime.Serialization.DataContract(IsReference = true)]
[System.ComponentModel.DataAnnotations.ScaffoldTable(true)]
public class TestModel
{
[Display(Name="Schedule Name")]
[Required]
public string scheduleName;
}
And in my .cshtml file I have:
<li>
@Html.LabelFor(m => m.scheduleName)
@Html.TextBoxFor(m => m.scheduleName, Model.scheduleName)
@Html.ValidationMessageFor(m => m.scheduleName)
</li>
But for some reason my display name is not showing up (the label shows 'scheduleName')
I swear I have the same code in other classes and it seems to display just fine. Can anyone point out a reason why this would not work?
The DataAnnotationsModelMetadataProvider
works on properties. Your scheduleName
should be a property not "just" a field.
[System.Runtime.Serialization.DataContract(IsReference = true)]
[System.ComponentModel.DataAnnotations.ScaffoldTable(true)]
public class TestModel
{
[Display(Name="Schedule Name")]
[Required]
public string scheduleName { get; set; }
}
Note: According to the C# naming conventions your property names should be PascalCased.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With