クライアント側の検証が機能していません... 別のページで行ったのと同じプロセスが機能していますが、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();
.
.
.
}