I'm using ASP.NET MVC 2 and I'm struggling to understand how can I use the Html.LabelFor helpet method.
Assuming I have a model:
public class Person
{
public string FirstName { get; set; }
}
In my view, if I write:
<%: Html.LabelFor(model => model.FirstName) %>
What I get on the page is "FirstName". But I don't want that because it's not user-friendly. I want it to be "First Name".
How do I achieve that?
Thanks.
Just like this:
public class Person
{
[DisplayName("First Name")]
public string FirstName { get; set; }
}
System.ComponentModel.DisplayNameAttribute
You should also check out System.ComponentModel.DataAnnotations for some incredibly helpful validation attributes like [Range(0, 100)]
, [StringLength(100)]
, [Required]
and more.
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