(a) contyolles public actionresult checkuserid (string id) { // string[] s = new string[] {"1", "2", "3"}; BOOL New ZHUCEBF (). Yanzheng (ID); = IsOK; return Partialview (); }
(ii) model public bool Yanzheng ( ID) {
var query = Context.zhuce.Where (p=>p.userid== id); if (query.) Count () >0 ) { return false ; return true ; }
(iii) view@{ "checkuserid"; @{ bool IsOK = (bool) Viewbag.data; if(IsOK) { <div> ask you to start registering </div> } else { <div> user name already exists </div> } }<
(d) Show this button on the home page"Viewport"Content="Width=device-width"/> <title>Add</title> <script src= "~/js/jquery-1.7.1.min.js" ></script> <script langugage= "JavaScript" > Func tion Checkuid () {var s = $ ("#userID"). Val (); $ ("#ss"). Load ("/home/checkuserid/" + s); } </script> (iv) The following view interface<tr>@using (Html.BeginForm ("Insert", "Home", FormMethod.Post)) {<td> <div id= "DD" ></div> @using (Html.BeginForm ("," ")) {<div> @Html. TextBox ("UserID") <input type= "button" value= "Check unique" onclick= "Checkuid ()"/> <span id= "ss" >& Lt;/span> </div>}</td> <td> @Html. TextBox ("UserName",NULL) </td><br/> <td> @Html. Password ("userpwd") </td><br/> <td> @Html. Password ("Mima") </td><br/> <td> <input type="Submit"Value="Register"></td> } </tr>
★(v) Add a JS file, add the use JS
MVC (Connect database) button unique validation