我似乎无法使用以下部分视图进行客户端验证工作。此视图位于父视图的 divTSettings div 内。从 stackoverflow 和其他网站尝试了很多东西,似乎没有任何效果。有任何想法吗?
<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="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
@using (Ajax.BeginForm("CreateT", "TAdmin", null,
new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "divTSettings"},
new { id = "CreateTForm" }))
{
<div>
<label>Name:</label>
<input type="text" name="tName" id="tName"/>
@Html.ValidationMessage("tName")
<input type="submit" value="Submit"/>
</div>
}
<script type="text/javascript">
$(function() {
$('#CreateTForm').validate({
rules: {
tName: {
required: true
}
},
messages: {
tName: {
required: 'Name required'
}
}
});
$("#CreateTForm").removeData("validator");
$("#CreateTForm").removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse("#CreateTForm");
});
</script>