相比之前用xmlhttprequest来说,不用考虑浏览器兼容的问题,这也是使用是Jquery这个轻量级框架的特点之一。下面学步园小编来讲解下JQuery+Asp.netMVC怎么样实现用户名?
JQuery+Asp.netMVC怎么样实现用户名
此处用的是ASP.NETMVCRC,aspx代码如下:
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="TestValidation1.aspx.cs"Inherits="DemoMVCForm.Views.FormDemo.TestValidation1"%>
$(document)。ready(function(){
$("#form-sign-up")。validate({
rules:{
login:{
required:true,
//hereinvokerelatedaction
remote:'<%=Url.Action("IsLoginAvailable","FormDemo")%>'
}
},
messages:{
login:{
required:"请输入用户名",
remote:jQuery.format("{0}已经有人用了")
}
},
//setthisclasstoerror-labelstoindicatevalidfields
success:function(label){
//setastextforIE
label.html("")。addClass("checked");
JQuery+Asp.netMVC怎么样实现用户名
}
});
});
Demo表单
用户名(试试输入Petter):