MVC提交表单(方法二)

  • A+
所属分类:MVC

MVC提交表单(方法二)

Views

  1. <div class="form-group">  
  2.    <label class="col-sm-3 control-label">城市:</label>  
  3.       <div class="col-sm-8">  
  4.          <input id="SB_CITY" name="SB_CITY" class="form-control" type="text" disabled>  
  5.       </div>  
  6.    </div>  
  7.   <div class="form-group">  
  8.      <label class="col-sm-3 control-label">服务商代码:</label>  
  9.           <div class="col-sm-8">  
  10.                 <input id="SB_COOP_ONLYKEY" name="SB_COOP_ONLYKEY" class="form-control" type="text" disabled>  
  11.           </div>  
  12.    </div>  
  13.  <div class="modal-footer">  
  14.     <button id="tjsb" class="btn btn-primary" type="button" onclick="SB_Base_add();">提交</button>  
  15.  </div>  

Ajax

  1. function SB_Base_add() {  
  2.     $.ajax({  
  3.         type: "POST",  
  4.         url: "/SB_Base/SB_Base_add",  
  5.         data: "sbcity=" + document.getElementById("SB_CITY").value +  
  6.              "&sbcooponlykey=" + document.getElementById("SB_COOP_ONLYKEY").value,  
  7.         success: function (data) {  
  8.             if (data == 0) {  
  9.                 swal("添加成功!""你成功添加了一条数据""success");  
  10.                 document.location.reload();  
  11.                 return true;  
  12.             }  
  13.         }  
  14.     });  
  15. }  

Controllers

  1. public void SB_Base_add()//添加  
  2.         {  
  3.             string sbcity = Request.Params["sbcity"];  
  4.             string sbcooponlykey = Request.Params["sbcooponlykey"];  
  5.            
  6.             sb_base_year.SB_CITY = sbcity;  
  7.             sb_base_year.SB_COOP_ONLYKEY = sbcooponlykey;  
  8.             entities.SB_BASE_YEAR.Add(sb_base_year);  
  9.             entities.SaveChanges();  
  10.             Response.Write("0");  
  11.         }  
钰玺

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:2   其中:访客  1   博主  1

    • 7L 7L 1

      6666

        • cuiyuxi cuiyuxi Admin

          @7L :grin: