我试图从Here下面的教程来实现远程验证,但它不是在我的案子我的代码如下 Web.Conf远程验证不工作
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="CrystalImageCleaner-AutoStart" value="true" />
<add key="CrystalImageCleaner-Sleep" value="60000" />
<add key="CrystalImageCleaner-Age" value="120000" />
</appSettings>
网站。掌握
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript" src="<%=Url.Content("~/Scripts/jquery.validate.unobtrusive.js")%>"></script>
查看
<div class="editor-field">
<%= Html.TextBoxFor(model => model.CNIC)%>
<%= Html.ValidationMessageFor(model => model.CNIC)%>
</div>
控制器
public ActionResult CheckDuplicate(string myvar)
{
return Json(!myvar.Equals("362-662-1"), JsonRequestBehavior.AllowGet);
}
型号
[Remote("CheckDuplicate", "Home", "Already Exists")]
在Firebug我得到下面的输出是从exptected
<input type="text" value="" name="uname" id="uname" data-val-required="This Field is Required" data-val="true">
while tutorial shows the following for its textbox
<input type="text" value="" name="UserName" id="UserName" data-val-required="The UserName field is required." data-val-remote-url="/Validation/IsUID_Available" data-val-remote-additionalfields="*.UserName" data-val-remote="&#39;UserName&#39; is invalid." data-val-regex-pattern="(\S)+" data-val-regex="White space is not allowed" data-val-length-min="3" data-val-length-max="6" data-val-length="The field UserName must be a string with a minimum length of 3 and a maximum length of 6." data-val="true" class="text-box single-line">
相似的问题是另一个页面: http://stackoverflow.com/a/37366502/4146766 – 2016-05-21 18:40:20