Summary of several forms of MVC form form submission

Source: Internet
Author: User
Several forms of form form submission in MVC

First Way: Submit button Submission

<form action= "Mydemand" method= "POST" >     <span> keywords:</span> <input name=     "keywords" type= "Text" value= "@keywords"/>    <input type= "Submit" value= "search"/>  </form>

The second way: $ ("#dataform"). Ajaxsubmit () Submit

<form id= "DataForm" action= "Updateuserinfo" enctype= "Multipart/form-data" method= "POST" >     <table style= "width:100%;border:0;" cellpadding= "0" cellspacing= "0" >       <tbody>         <tr>           <td width= "40" > Name:</td>           <td><input type= "text" name= "Nvc_name" id= "Nvc_name" value= "@Model. Nvc_name"/> </td>         </tr>         <tr>           <td colspan= "2" align= "center" >             <input type= "button" Value= "Save" id= "Btnsubmit"/>           </td>         </tr>       </tbody>     </table>   </form>

<script src= "Http://code.jquery.com/jquery-1.11.0.min.js" ></script><script src= "/http Malsup.github.io/jquery.form.js "></script>//ajaxform dependent script <script type=" Text/javascript ">  $ ( Document). Ready (function () {    $ ("#btnsubmit"). Click (function () {if ("[Name= ' Nvc_name ']"). val () = = "") {        Alert ("Please fill in the name");        $ ("[name= ' Nvc_name ']"). focus ();        return;      }      $ ("#dataform"). Ajaxsubmit (function (r) {        alert (r.msg);        if (r.success) {          location.reload ();}})})  ; </script>

Third Way: Post submission

<table style= "width:100%;border:0px;" cellpadding= "0" cellspacing= "0" >  <tbody>    <tr>      <td width= "15%" align= "right" > Mobile phone number:</td>      <td><input type= "text" placeholder= "Please enter phone number" Id= "Nvc_user_name"/></td>    </tr>    <tr>      <td colspan= "2" align= "Center" >        <input type= "button" value= "Save" id= "Btnsubmit"/>      </td>    </tr>  </tbody></ Table>

<script type= "Text/javascript" >$ (function () {    $ ("#btnsubmit"). Click (function () {      var nvc_user_name = document.getElementById (' Nvc_user_name ');      $.post ('/interface/modefiypwd ', {        nvc_user_name:nvc_user_name.value,      }, function (data) {        if ( data.success) {          $ ("#successdiv"). Show ();          $ ("#editdiv"). Hide ();        }        else {          layer.msg (data. (MSG);});})  </script>

Fourth: Add the OnClick event validation form for the button in from and submit

<form method= "POST" action= "Recordedit" id= "DataForm" >  <table width= "100%" border= "0" cellspacing= "0" cellpadding= "0" >    <tr>      <td align= "right" > App path:</td>      <td>        <input Type= "text" name= "Nvc_app_path" id= "Nvc_app_path" >      </td>    </tr>    <tr class= "B_TR2" >      <td><input type= "button" onclick= "Checkform ()" Value= "Save" ></td>    </tr>  </table></form>

<script src= "Http://libs.baidu.com/jquery/1.7.2/jquery.js" ></script><script src= "~/scripts/layer/ Layer.js "></script><script type=" text/javascript ">  function Checkform ()  {    if ($ (" # Nvc_app_path "). Val (). length = = 0) {      layer.tips (" The application path cannot be empty "," #nvc_app_path ");      return;    }    $ ("#dataForm"). Submit ();  } </script> <br>
  • Related Article

    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.