I want to create an extension method for HtmlHelper that allows me to create a LabelFor a property display an asterisk after it if it is a required field. How can I do that?
public class Foo
{
[Required]
public string Name { get; set; }
}
Html.LabelFor(o => o.Name) // Name*
Here is an blog post that describes how to do this.
To give you a small example modified from the site above (note – I have not compiled/tested this):