我的模型看起来像:
public class MyViewModel
{
public MyViewModel()
{
MyClasses = new List<MyClass>();
}
public List<MyClass> MyClasses{ get; set; }
[Required(ErrorMessage = "is required.")]
public string Prop1{ get; set; }
[Required(ErrorMessage = "is required.")]
public int Prop2{ get; set; }
}
我在岗位上的控制器:
[HttpPost]
public ActionResult MyActionOnPost(MyViewModel model)
{
//save to DB
//Prop2 is not null but Prop1 is nulll. why??
}
查看代码:
@Html.TextBoxFor(m => m.Prop2) @Html.ValidationMessageFor(m => m.Prop2)
@Html.TextBoxFor(m => m.Prop1) @Html.ValidationMessageFor(m => m.Prop1)
Prop2
我可以在提交时看到价值,但Prop1
它是null
. 任何想法?