客户端验证不起作用...... 我在另一个页面中完成了相同的过程,但没有使用 forloop。在这里,当我在不进行验证的情况下键入文本时,只需勾选图像正在显示...给我解决方案..
视图是
@model IList<clientval.Models.ShoppingClass>
@using (Html.BeginForm("Login", "Home"))
{
for (int i =0; i <1; i++)
{
<table>
<tr>
<td>@Html.Label("FirstName")</td>
<td>@Html.TextBox("FirstName")<div>@Html.ValidationMessageFor(o => o[i].FirstName)</div></td>
<td>@Html.Label("LastName")</td>
<td>@Html.TextBox("LastName")<div>@Html.ValidationMessageFor(o => o[i].LastName)</div></td>
<tr>
}
}
脚本是
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
<script src="../../assets/js/ClientScript.js" type="text/javascript"></script>
控制器是
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Guestlogin(string firstname, string lastname)
{
ShoppingClass s = new ShoppingClass();
var button = Request["button"];
var ob = s.Newcustomer(customerfirstname, customerlastname);
TempData["BN"] = ob;
return RedirectToAction("Sucessfully", ob);
}
型号是
[Required(ErrorMessage = "First Name is Required")]
[RegularExpression(@"^[a-zA-Z ]*$", ErrorMessage = "First Name is Not valid")]
public string FirstName { get; set; }
[Required(ErrorMessage = "Last Name is Required")]
[RegularExpression(@"^[a-zA-Z ]*$", ErrorMessage = "Last Name is Not valid")]
public string LastName { get; set; }
public List<ShoppingClass> Newcustomer(string firstname, string lastname)
{
List<ShoppingClass> list = new List<ShoppingClass>();
ShoppingClass obj = new ShoppingClass();
.
.
.
}