我试图在不使用 Unobtrusive Validation 的情况下验证我的表单,因为我的验证比一般的要复杂一些。需要什么来实现这一点?只需将 Validation.js 脚本包含到我的文件中并写出 jquery 代码?这就是我到目前为止所取得的成就......
$(document).ready(function () {
$("#formSearchByMRN").validate({
rules: {
MRN: { required: true, minLength: 6 }
},
messages: {
MRN: 'Please Enter a Valid MRN'
}
});
});
但是,每当我提交表单时,都没有经过验证?这是我的表格...
@using (Html.BeginForm("SearchByMRN", "SearchPatients", FormMethod.Post, new { id = "formSearchByMRN" }))
{
<p>
<ul>
<li>@Html.Label("MRN#", new { @for = "MRN" })<br />@Html.TextBox("MRN","", new { id = "MRN" })</li>
<li>@Html.Label("MRNDrop", new { @for = "MRNDrop" })<br /> @Html.DropDownList("MRNDrop", (List<SelectListItem>)TempData["MRNLIST"], new { id = "MRNDrop" })</li>
</ul>
</p>
<input type="submit" value="Search by MRN" id="submitMRN"/>
}
我错过了什么。我的 _layout.cshtml 文件中有我的 jquery Valition 脚本。