Nullable属性使模型无效

时间:2017-03-14 13:01:08

标签: c# asp.net-mvc

有人可以解释为什么以下模型在LogIn操作方法中无效吗?我该怎么做才能解决它?

public class EmployeeViewModel
{
    public int? EmployeeId { get; set; }
    public string EmployeeName { get; set; }
    public string EmployeeEmailId { get; set; }
}

HomeController中:

public ActionResult Index()
{
    EmployeeViewModel evm = new EmployeeViewModel();
    evm.EmployeeEmailId = "sdf@gmail.com";

    return LogIn(evm);
}

public ActionResult LogIn(EmployeeViewModel modelEnt)
{
    if (ModelState.IsValid)     //Invalid Employee Id
    {
        ...
    }
}

0 个答案:

没有答案