-1
フォームでユーザーが入力したフィールドを検証しようとしています。私はこれを試しましたが、フィールドを検証していません。私がレコードを入力しなくても、エラーメッセージは表示されません。スクリプトやライブラリのように追加する必要があるものはありますか? どのライブラリを追加しますか?Asp.netのAttribiute検証mvc
ビューモデル(クラス):常にRedirectToAction
メソッドを使用してRedirectResultを返しているあなたのHttpPostアクションで
<form action="@Url.Action("Index","SignUp")" class="form-horizontal" method="post">
Full Name @Html.TextBoxFor(x => x.Full_Name, new { @class = "form-control" })
@Html.ValidationMessageFor(x=>x.Full_Name)
<br />
Email @Html.TextBoxFor(x => x.Email, new { @class = "form-control" })
@Html.ValidationMessageFor(x => x.Email)
<br />
Password @Html.TextBoxFor(x => x.pass, new { @class = "form-control", type = "password" })
@Html.ValidationMessageFor(x => x.pass)
<br />
Date of Birth @Html.TextBoxFor(x => x.Date_of_Birth, new { @class = "form-control" })
@Html.ValidationMessageFor(x => x.Date_of_Birth)
<br />
Address @Html.TextBoxFor(x => x.Home_Address, new { @class = "form-control" })
@Html.ValidationMessageFor(x => x.Home_Address)
<br />
Mobile Number-1 @Html.TextBoxFor(x => x.Mobile_Number1, new { @class = "form-control" })
@Html.ValidationMessageFor(x => x.Mobile_Number1)
<br />
CNIC @Html.TextBoxFor(x => x.CNIC, new { @class = "form-control" })
@Html.ValidationMessageFor(x => x.Full_Name)
<br />
Country @Html.TextBoxFor(x => x.Country, new { @class = "form-control" })
@Html.ValidationMessageFor(x => x.Country)
<br />
Provience @Html.TextBoxFor(x => x.Provience, new { @class = "form-control" })
@Html.ValidationMessageFor(x => x.Provience)
<br />
City @Html.TextBoxFor(x => x.City, new { @class = "form-control" })
@Html.ValidationMessageFor(x => x.City)
<br />
@{
List<SelectListItem> listItems = new List<SelectListItem>();
listItems.Add(new SelectListItem
{
Text = "Student",
Value = "Student"
});
listItems.Add(new SelectListItem
{
Text = "Trainer",
Value = "Trainer",
Selected = true
});
}
@Html.DropDownListFor(model => model.User_Role, listItems, "-- Select Role --")
@Html.ValidationMessageFor(x => x.User_Role)
<br />
<br />
@{
List<SelectListItem> listItems2 = new List<SelectListItem>();
listItems2.Add(new SelectListItem
{
Text = "Male",
Value = "Male"
});
listItems2.Add(new SelectListItem
{
Text = "Female",
Value = "Female",
Selected = true
});
}
@Html.DropDownListFor(model => model.Gender, listItems2, "-- Select Gender --")
@Html.ValidationMessageFor(x => x.Gender)
<br />
<br />
<button type="submit" class="btn btn-primary"> Sign Up </button>
あなたのhttppostアクションメソッドはどのように見えますか? – Shyju
[HttpPost] 公共のActionResultインデックス(RegisterationLoginViewModelのSVM) {IF(SVM == NULL){ RedirectToAction( "Null_SignUp_View")。 } 文字列RegisterStudent_Response = db.Register(svm); if(RegisterStudent_Response == "1") { RedirectToAction( "ThankYou_View"); } return RedirectToAction( "ThankYou_View"); } –