MVC (Connection database) button unique validation

Source: Internet
Author: User

(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.