<input type="text" id="Name" value="" placeholder="請輸入帳號" /> <input type="password" id="Password" value="" placeholder="請輸入密碼" /> <input type="button" id="btn" value="提交 " />
public ActionResult Index() { return View(); } public string JqueryPost() { string Name = Request["Name"].ToString(); string Pwd = Request["Password"].ToString(); return "Name:" + Name + "Pwd:" + Pwd; }
3.JSjquery
<script src="~/Content/js/jquery-2.2.4.min.js"></script> <script> $(function () { $('#btn').click(function () {//點擊提交按鈕觸發點擊事件 $.post( "/Headquarter/JqueryPost",//請求的控制器方法(url) { Name: $('#Name').val(), Password: $('#Password').val() },//發送數據到控制器,鍵值對形式 (data) function (data) {//獲取控制器傳過來的數據(回調函數) layer.alert(data); }) }); }); </script>
4.運行異步