Reputation: 127
My model is
public class RegisterViewModel
{
[Required]
[Display(Name = "User name222")]
public string UserName { get; set; }
}
My view is
@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
It's display "UserName",not "User name222".
And the ErrorMessage display "The User name222 field is required."
============================================== All the code is VS14 CTP2 Asp.net Vnext Web Application automatic generation.
Why?How to fix it?
Upvotes: 1
Views: 389
Reputation: 216
This issue is being tracked and it is being addressed as we speak.
Thanks, Kirthi
Upvotes: 1
Reputation: 103
UserName is the Propoerty which you want the controller to know the property by that name , Dispaly Method will set your property to that Name .assign some value to the Property UserName in a Constructor like.
public class RegisterViewModel
{
[Required]
[Display(Name = "UserName")]
public string UserName { get; set; }
public RegisterViewModel(RegisterViewModel model)
{
model.UserName = "user 123";
this.UserName = model.UserName;
}
}
and here when you are calling in your view please use the "null" parameter in html helper as @Html.LabelFor(m => m.UserName,null, new { @class = "col-md-2 control-label" })
Upvotes: 1