MVC (串連資料庫)按鈕 唯一驗證

來源:互聯網
上載者:User

標籤:

(一) contyolles      public ActionResult CheckUserID(string id)        {         //   string[] s = new string[] { "1", "2", "3" };            bool isOK = new zhuceBF().yanzheng(id);            ViewBag.Data = isOK;            return PartialView();        }                
(二) model   public bool yanzheng(string id)        {            var query = context.zhuce.Where(p=>p.userID==id);            if (query.Count()>0)            {                return false;            }            return true;                }
(三)view@{    ViewBag.Title = "CheckUserID";}<h2>視窗訊息</h2><div>    @{        bool isOK = (bool)ViewBag.Data;        if(isOK)        {                   <div>請您開始註冊</div>        }        else        {            <div>使用者名稱已存在</div>        }    }<
(四)在首頁上顯示這個按鈕<head>    <meta name="viewport" content="width=device-width" />    <title>Add</title>  <script src="~/js/jquery-1.7.1.min.js"></script>    <script langugage="javascript">        function checkUID() {            var s = $("#userID").val();            $("#ss").load("/Home/CheckUserID/" + s);        }    </script>       </head><body>(四)下面的視圖介面  <tr>             @using (Html.BeginForm("Insert", "Home",FormMethod.Post)) {                      <td>                    <div id="dd"></div>                  @using(Html.BeginForm("","")){                     <div>                 @Html.TextBox("userID")  <input type="button" value="檢查唯一" onclick="checkUID()" /> <span id="ss"></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="註冊"></td>                     }   </tr>

★(五)添加一個JS的檔案,添加使用JS 

 

MVC (串連資料庫)按鈕 唯一驗證

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.