jquery - Button submitting form to "Get" ActionResult instead of "Post" -


i took on mvc web application employee no longer company work for. application in development stage , noticed unresolved error 'submit' button triggers view's corresponding httpget actionresult, instead of httppost actionresult.

he included lot of jquery scripts in view, , suspected 1 of them causing issue, none seem apply directly button.

controller (named homecontroller.cs):

[httpget]     public actionresult create(string distributorobject)     {         stockliftobjectview stockliftobjectview = new stockliftobjectview();         var userinfo = user.identity.name.getactivedirectoryinfo();         stockliftobjectview.txtfirstname = userinfo.firstname;         stockliftobjectview.txtlastname = userinfo.lastname;         stockliftobjectview.txtemail = userinfo.email;          if (stockliftobjectview.regionid == guid.empty)         {             stockliftobjectview.regionslist = new selectlist(_stockliftservice.getregions(), "id", "regionname");         }          return view(stockliftobjectview);     }      [httppost] //haven't done here yet. ths never reached     public actionresult create(string command, stockliftobjectview stockliftobjectview)     {         return view(stockliftobjectview);     } 

view (named create.cshtml):

@using html.beginform("create", "home", formmethod.post, new {id = createstocklift})) {      //left out non-useful code here     <div class="col-md-offset-2 col-md-10">                 <table>                     <tr><td><input type="submit" value="create" name="command" class="btn btn-default" /></td></tr>                     <tr><td><input type="submit" value="save" name="command" class="btn btn-default" /></td></tr>                 </table>     </div> } 

script in view thought problematic:

<script type="text/javascript">  function getview() {          //runs everytime page loads          $.get("@url.action("showpartial", "stockliftattachmentwebgrid",  new     list<hpd.lynx.web.stocklift.stockliftattachmentupload>()))", function (data) {             $("#stockliftattachmentpartial").replacewith(data);             $('#createstocklift').submit();             });          };         $("#stockliftattachmentpartial").show(); </script> 

i'm sorry question isn't specific. i've been baffled issue past couple of days , can't think of way describe problem in google search. said before, i'm not versed jquery think misunderstanding simple.

update:

only other time getview() function referenced here...

<input type="submit" value="upload file" title="upload" id="btnupload" onclick="javascript: getview(); return false;" /> 

so don't understand why executes when page loads (i never click upload button). again, misunderstanding coming never using more basic scripts.

other scripts in view (don't seem applicable i'll show in case)

<script>     $(function () {         $('#search').click(function () {             var distributornumber = $("#textboxdistributornumber").val();             var href = this.href + '?distributornumber=' + distributornumber;             @*var url = "@url.action("distributorpartial", "distributor")"*@             $('#dialog').dialog({                 width: 1175,                 height: 500,                 title: 'distributor search',                 modal: true,                 open: function (event, ui) {                     $(".ui-dialog-titlebar-close").hide();                     $(this).load(href, function (result) {                         $('.forms').submit(function () {                              $.ajax({                                 url: this.action,                                 type: this.method,                                 data: $(this).serialize(),                                 success: function (json) {                                     debugger;                                     $('#distributorviewmodel_distributorname').val(json.distributorname);                                  }                             });                             return false;                         });                     });                 }             });             return false;         });     }); </script> 

<!doctype html>  <html>  <head>      <meta charset="utf-8" />      <meta name="viewport" content="width=device-width, initial-scale=1.0">      <title>create</title>       <link rel="stylesheet" type="text/css" href="http://hco/css/main.css" />              <link href="/content/site.css" rel="stylesheet"/>        <link href="/content/themes/base/jquery.ui.theme.css" rel="stylesheet"/>          <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />      <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>      <script type="text/javascript" src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>        <script src="/scripts/jquery.ui.datepicker.min.js"              type="text/javascript"></script>      <script src="/scripts/datepickerready.js"              type="text/javascript"></script>        <script src="/scripts/modernizr-2.7.2.js"></script>                                     </head>  <body>      <form id="form1" runat="server">          <div align="center">              <table border="0" width="800" bgcolor="black" cellpadding="0" cellspacing="0">                  <tr>                      <td>                          <table border="0" cellpadding="0" cellspacing="0" width="800px">                              <tr bgcolor="black" height="60px">                                                  <%--add filler, srm 2/13/2012--%>                                  <td align="left" class="apptitle" style="width:100%;">                                      <!--the title here-->                                                                                                              </td>                                  <td valign="top" align="right">                                      <table border="0" cellpadding="0" cellspacing="0">                                          <tr>                                                                                       </tr>                                          <tr valign="middle">                                              <td><input style="padding:0,0,0,0;margin:0,0,0,0;" height="20px" type="text" name="txtsearch" id="txtsearch" /></td>                                              <td><image height="22px" width="22px" style="background-color:white;padding:0,0,0,0;margin:0,0,0,0;" src="http://hco/images/searchbutton.jpg" alt="search" onclick="window.location='/site-search.aspx?search=' + document.all.txtsearch.value.trim()" onmouseover="this.style.cursor='hand'" />&nbsp;</td>                                          </tr>                                      </table>                                  </td>                              </tr>                              <tr height="24px">                                  <td colspan="2" class="hconav">                                      <table border="0" cellpadding="2" cellspacing="0" height="24" width="100%">                                          <tr>                                                                                           <td></td>                                              <td nowrap="nowrap" align="right">                                                  <table border="0" cellpadding="0" cellspacing="0">                                                      <tr>                                                         </tr>                                                  </table>                                              </td>                                          </tr>                                      </table>                                  </td>                              </tr>                              <tr>                                  <td colspan="3" bgcolor="white" height="100%" valign="top" style="margin:0,0,0,0;">                                      <div style="padding:10px;">                                          <div id="page">                                                <div class="container body-content">                                                                                                              <form action="/home/create" id="createstocklift" method="post"><input name="__requestverificationtoken" type="hidden" value="xz4yzzvuuxup-g5kckprb6ox3dz668tjmh6fkiiwl52zsnvjx-dfv0xdnvwakmplgpcbm664tdijdwwowueo70et9nwspgwsrv0dvxogdyylma3d3czveh2vzj0ftr6o0" />    <style type="text/css">          .style1 {              height: 35px;          }      </style>      <br />      <div id="lblrequired" align="center">          <label for="lblrequired">* required saving</label>      </div>      <div align="center">          <div style="text-align: left; clear: none;">              <table cellpadding="2" border="1" align="center">                    <tr>                      <td>                          <b>*ctm first name:</b>                      </td>                      <td>                          <input class="textboxfirstname" id="txtfirstname" name="txtfirstname" type="text" value="" />                          <span class="field-validation-valid" data-valmsg-for="txtfirstname" data-valmsg-replace="true"></span>                      </td>                  </tr>                  <tr>                      <td>                          <b>*ctm last name</b>                      </td>                      <td>                          <input class="textboxlastname" id="txtlastname" name="txtlastname" type="text" value="" />                          <span class="field-validation-valid" data-valmsg-for="txtlastname" data-valmsg-replace="true"></span>                      </td>                  </tr>                  <tr>                      <td>                          <b>*ctm email:</b>                      </td>                      <td>                          <input class="textboxemail" id="txtemail" name="txtemail" type="text" value="" />                          <span class="field-validation-valid" data-valmsg-for="txtemail" data-valmsg-replace="true"></span>                      </td>                  </tr>                  <tr>                      <td>                          <b>*your region:</b>                      </td>                      <td>                          <select data-val="true" data-val-required="the regionid field required." id="regionid" na               <span class="field-validation-valid" data-valmsg-for="regionid" data-valmsg-replace="true"></span>                        </td>                  </tr>                  <tr>                      <td>                          <b>*distributor:</b>                      </td>                      <td>                          <label class="control-label col-md-2" for="distributor_number_search_text:_">distributor number search text: </label>                          <input id="textboxdistributornumber" name="distributor" type="text" value="" /> <br />                          <label class="control-label col-md-2" for="distributor_customer_name_search_text:_">distributor customer name search text: </label>                          <input id="textboxdistributorname" name="distributorprincipalapprovalid" type="text" value="" />                              <div id="dialog" title="basic dialog">please wait</div>                          <a href="/distributor/distributorpartial" id="search">search</a>                                                    <div id="divdistributor">                              <input class="text-box single-line" id="distributorviewmodel_distributorname" name="distributorviewmodel.distributorname" type="text" value="" />                          </div>                          <span class="field-validation-valid" data-valmsg-for="distributor" data-valmsg-replace="true"></span>                        </td>                  </tr>                    <tr>                      <td>                          <b>end user:</b>                      </td>                      <td></td>                  </tr>                  <tr>                      <td>                          <b><label class="control-label col-md-2" for="accountmanufactures">account manufactures:</label></b>                      </td>                      <td>                          <input class="textboxaccountmanufactures" id="accountmanufactures" name="accountmanufactures" type="text" value="" />                          <span class="field-validation-valid" data-valmsg-for="accountmanufactures" data-valmsg-replace="true"></span>                      </td>                  </tr>                  <tr>                      <td>                          <b><label class="control-label col-md-2" for="inventoryremovedfrom">inventory removed from:</label></b>                      </td>                      <td>                          <input class="textboxinventoyremovedfrom" id="inventoryremovedfrom" name="inventoryremovedfrom" type="text" value="" />                          <span class="field-validation-valid" data-valmsg-for="inventoryremovedfrom" data-valmsg-replace="true"></span>                      </td>                  </tr>                  <tr>                      <td>                          <b><label class="control-label col-md-2" for="annualpotentialvalue">*annual potential hpd products:</label></b>                      </td>                      <td>                          <input class="textboxannualpotentialvalue" data-val="true" data-val-number="the field *annual potential hpd products: must number." id="annualpotentialvalue" name="annualpotentialvalue" type="text" value="" />                          <span class="field-validation-valid" data-valmsg-for="inventoryremovedfrom" data-valmsg-replace="true"></span>                      </td>                  </tr>                  <tr>                      <td>                          <b><label class="control-label col-md-2" for="inventoryvalue">*competitive inventory value:</label></b>                      </td>                      <td>                          <input class="text-box single-line" data-val="true" data-val-number="the field *competitive inventory value: must number." id="inventoryvalue" name="inventoryvalue" type="text" value="" />                          <span class="field-validation-valid" data-valmsg-for="inventoryvalue" data-valmsg-replace="true"></span>                      </td>                  </tr>                  <tr>                      <td>                          <b><label class="control-label col-md-2" for="fiftypercentmultiplier">*50% (.50) multiplier:</label></b>                      </td>                      <td>                          <input class="text-box single-line" data-val="true" data-val-number="the field *50% (.50) multiplier: must number." id="fiftypercentmultiplier" name="fiftypercentmultiplier" type="text" value="" />                          <span class="field-validation-valid" data-valmsg-for="fiftypercentmultiplier" data-valmsg-replace="true"></span>                      </td>                  </tr>                  <tr>                      <td>                          <b><label class="control-label col-md-2" for="creditduevalue">*credit due distributor:</label></b>                      </td>                      <td>                          <input class="text-box single-line" data-val="true" data-val-number="the field *credit due distributor: must number." id="creditduevalue" name="creditduevalue" type="text" value="" />                          <span class="field-validation-valid" data-valmsg-for="creditduevalue" data-valmsg-replace="true"></span>                      </td>                  </tr>                  <tr>                      <td>                          <b><label class="control-label col-md-2" for="initialordervalue">*value of initial order:</label></b>                      </td>                      <td>                          <input class="text-box single-line" data-val="true" data-val-number="the field *value of initial order: must number." id="initialordervalue" name="initialordervalue" type="text" value="" />                          <span class="field-validation-valid" data-valmsg-for="initialordervalue" data-valmsg-replace="true"></span>                      </td>                  </tr>                  <tr>                      <td>                          <b><label class="control-label col-md-2" for="stockliftmaterialscrappeddate">stocklift material scrapped(date):</label></b>                      </td>                      <td>                          <input class="text-box single-line" data-val="true" data-val-date="the field stocklift material scrapped(date): must date." id="stockliftmaterialscrappeddate" name="stockliftmaterialscrappeddate" type="datetime" value="" />                          <span class="field-validation-valid" data-valmsg-for="stockliftmaterialscrappeddate" data-valmsg-replace="true"></span>                      </td>                  </tr>                  <tr>                      <td>                          <b><label class="control-label col-md-2" for="distributorprincipalapprovalid">distributor principal (signature):</label></b>                      </td>                      <td>                          <input class="text-box single-line" id="distributorprincipalapprovalid" name="distributorprincipalapprovalid" type="text" value="" />                          <span class="field-validation-valid" data-valmsg-for="distributorprincipalapprovalid" data-valmsg-replace="true"></span>                            <b><label class="control-label col-md-2" for="distributorprincipalapprovaldate">date:</label></b>                          <input class="text-box single-line" data-val="true" data-val-date="the field date: must date." id="distributorprincipalapprovaldate" name="distributorprincipalapprovaldate" type="datetime" value="" />                          <span class="field-validation-valid" data-valmsg-for="distributorprincipalapprovaldate" data-valmsg-replace="true"></span>                            <div id="distributordiv">                          </div>                        </td>                  </tr>                  <tr>                      <td>                          <b><label class="control-label col-md-2" for="comments">comments:</label></b>                      </td>                      <td>                          <textarea class="textboxcomments" cols="55" id="comments" name="comments" rows="10">  </textarea>                          <span class="field-validation-valid" data-valmsg-for="comments" data-valmsg-replace="true"></span>                      </td>                  </tr>                  <tr>                      <td>                          <b><label class="control-label col-md-2" for="administrativenotes">administrative notes:</label></b>                      </td>                      <td>                          <textarea class="textboxadministrativenotes" cols="55" id="administrativenotes" name="administrativenotes" rows="10">  </textarea>                          <span class="field-validation-valid" data-valmsg-for="administrativenotes" data-valmsg-replace="true"></span>                      </td>                  </tr>                  <tr>                      <td>                          <b><label class="control-label col-md-2" for="rejectedreason">rejected reason:</label></b>                      </td>                      <td>                          <textarea class="textboxrejectedreason" cols="55" id="rejectedreason" name="rejectedreason" rows="10">  </textarea>                          <span class="field-validation-valid" data-valmsg-for="rejectedreason" data-valmsg-replace="true"></span>                      </td>                  </tr>                                    <tr>                      <td>                          <b><label class="control-label col-md-2" for="filename">stocklift attachment:</label></b>                      </td>                      <td>                          <input type="file" name="files" value="" multiple="multiple" />                          <input type="submit" value="upload file" title="upload" id="btnupload" onclick="javascript: getview(); return false;" />                            <div style="color:red;font-size:14px"></div>                      </td>                  </tr>              </table>          </div>      </div>      <div id="stockliftattachmentpartial">                </div>              <div class="col-md-offset-2 col-md-10">                  <table>                      <tr><td><input type="submit" value="create" name="command" class="btn btn-default" /></td></tr>                                                                  <tr><td><input type="submit" value="save" name="command" class="btn btn-default" /></td></tr>                  </table>              </div>  </form><table>      <tr><td>&nbsp;</td></tr>      <tr>          <td align="left"><a href="/">back list</a></td>      </tr>    </table>                                                        </div>                                            </div>                                        </div>                                  </td>                          </table>                      </td>                  </tr>              </table>          </div>      </form>                    <script type="text/javascript">                         function getview() {                $.get("/stockliftattachmentwebgrid/showpartial?capacity=0&amp;count=0)", function (data) {                  $("#stockliftattachmentpartial").replacewith(data);                  $('#createstocklift').submit();              });            };          $("#stockliftattachmentpartial").show();                            //{            //    $.get("<~/controllers/stockliftattachmentwebgridcontroller/showpartial()>", function (data) { $("#stockliftattachmentpartial").html(data); }          //)          //}              //$('#stockliftattachmentpartial').load('/views/stockliftattachmentwebgrid/stockliftattachmentwebgrid');            </script>        <script>          // var $loading = $('#divdistributor').hide();            $(function () {              $('#search').click(function () {                  var distributornumber = $("#textboxdistributornumber").val();                  var href = this.href + '?distributornumber=' + distributornumber;                                    $('#dialog').dialog({                      width: 1175,                      height: 500,                      title: 'distributor search',                      modal: true,                      open: function (event, ui) {                          $(".ui-dialog-titlebar-close").hide();                          $(this).load(href, function (result) {                              $('.forms').submit(function () {                                    $.ajax({                                      url: this.action,                                      type: this.method,                                      data: $(this).serialize(),                                      success: function (json) {                                          //$('#dialog').dialog('close');                                          // $loading.show();                                          debugger;                                          $('#distributorviewmodel_distributorname').val(json.distributorname);                                        }                                  });                                  return false;                              });                          });                      }                  });                  return false;              });          });  </script>

update:

having seen full output page html, have nested <form> elements invalid , causing problems.

you need place forms not nested in dom hierarchy.

first thoughts:

just theory: if understand picture initial clues, problem may occur when "search" first. opens dialog, populates form, quite stupidly attaches permanent submit event handler every form exists on page @ time class="forms".

the following fix 1 piece of silliness:

      open: function (event, ui) {          var $panel = $(this);          $(".ui-dialog-titlebar-close").hide();          $panel.load(href, function (result) {               $('.forms', $panel).submit(function () { 

the fix add scope submit handler, e.g. $('.forms', $panel), not steal submits all .forms on page! target .forms in panel loaded.

advice: other jquery code, anywhere, uses submit( , regard potential problem.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -