asp.net mvc - LabelFor is showing property name instead of Display attribute -
my model is:
public class mymessage { [required, display(name= "recipient id")] public string recipient; [required, display(name ="message")] public string text; }
my view is:
@model mymessage @html.labelfor(m=>m.recipient) @html.textboxfor(m=>m.recipient) <br/> @html.labelfor(m => m.text) @html.textboxfor(m => m.text)
the rendered output showing property name instead of display attribute. have done wrong?
change fields in model properties
public class mymessage { [required, display(name= "recipient id")] public string recipient { get; set; } [required, display(name ="message")] public string text { get; set; } }
the modelmetadata.displayname
not set fields. , need anyway because defaultmodelbinder
not set value of fields, when submit form, values of recipient
, text
have been null
despite text entered in textboxes , modelstate
have been invalid because of [required]
attributes