我的模特是
public class RegisterViewModel
{
[Required]
[Display(Name = "User name222")]
public string UserName { get; set; }
}
我的观点是
@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
它的显示" 用户名",而不是" 用户名222 "。
ErrorMessage显示" 用户名222字段是必需的。"
============================================== 所有代码都是VS14 CTP2 Asp.net Vnext Web Application自动生成。
为什么?如何解决?
答案 0 :(得分:1)
UserName是您希望控制器通过该名称知道属性的Propoerty,Dispaly Method会将您的属性设置为该Name。为构造函数中的Property UserName分配一些值,如。
公共类RegisterViewModel
{
[Required]
[Display(Name = "UserName")]
public string UserName { get; set; }
public RegisterViewModel(RegisterViewModel model)
{
model.UserName = "user 123";
this.UserName = model.UserName;
}
}
在这里,当你在你的视图中调用时,请使用html helper中的“null”参数作为 @ Html.LabelFor(m => m.UserName,null,new {@class =“col-md-2 control-label”})
答案 1 :(得分:1)
这个问题正在tracked,我们发言时正在解决这个问题。
谢谢, Kirthi