1

我的模型是

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" })

显示的是“ UserName ”,而不是“ User name222 ”。

并且 ErrorMessage 显示“ The User name222 field is required.

===============================================所有代码都是VS14 CTP2 Asp.net Vnext Web Application 自动生成。

为什么?如何解决?

4

2 回答 2

1

我们正在跟踪这个问题,并在我们发言时解决这个问题。

谢谢,基尔蒂

于 2014-07-22T23:54:31.573 回答
1

UserName 是您希望控制器通过该名称知道属性的 Propoerty,Dispaly 方法会将您的属性设置为该名称。在构造函数中为 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 助手中的“null”参数作为 @Html.LabelFor(m => m.UserName,null, new { @class = "col-md-2 control-label" } )

于 2014-07-16T17:25:54.157 回答