运行后,当我在用户名文本框中输入值并单击提交按钮时。在控制器中,我检查对象显示的空值......如果我删除 forloop 并列出它的工作......给我一个解决方案
控制器 :
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(LogonViewModel lvm)
{
LogonViewModel lv = new LogonViewModel();
return View();
}
模型:
public class LogonViewModel
{
[Required(ErrorMessage = "User Name is Required")]
public string UserName { get; set; }
}
看法
@model IList<clientval.Models.LogonViewModel>
@{
ViewBag.Title = "Index";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="../../assets/js/val.js" type="text/javascript"></script>
@using (Html.BeginForm())
{
for (int i = 0; i < 1; i++)
{
@Html.LabelFor(m => m[i].UserName)
@Html.TextBoxFor(m => m[i].UserName)
@Html.ValidationMessageFor(per => per[i].UserName)
<input type="submit" value="submit" />
}
}