Click here to Skip to main content
15,884,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Any way to Save form data without Submitting form using $("#Form").serializeArray(). When I'm using serializeArray, it works only with form submit and not working with a button click

When i call this function in from cshtml page, I not getting form data in my controller (Model). My Code is,

JavaScript
function SaveCall() {
   $("#ItemData").val(JSON.stringify($("#jqxOpStockGrid").jqxGrid('getboundrows')));

  $.ajax({
    url: '/INVOpeningStock/create',
    type: 'POST',
    data: $("#INVOpeningStock_Form").serializeArray(),
    cache: false,
    aync: false,
    success: function (data) {
        if (!data.success) {

        } else {



        }
    }
});
}



Ajax call hitting in my controller method. But the parameter model was empty. My Controller Method is:


[HttpPost]
public ActionResult Create(INVOpeningStock invopeningstock )
   {
    //Method Body
   }


My cshtml Page Code is

HTML
@using (Html.BeginForm(new { id = "INVOpeningStock_Form" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset class="fieldset">
<table width="100%" align="center" class="textleft">
  <tr>
     <td width="20%">
         <div class="editor-label">
              @Html.LabelFor(model => model.cName)
         </div>
     </td>
     <td width="80%" align="left">
          <div class="editor-field">
              @Html.TextBoxFor(model => model.cName, new { maxlength = 50,  @class = "textbox mediumtxt reqtext" })
          </div>
          @Html.ValidationMessageFor(model => model.cName, "", new { @class =  "required" })
      </td>
   </tr>
 </table>
</fieldset>
Posted
Updated 3-Nov-14 19:23pm
v2

1 solution

I got data When I used

JavaScript
$("form").serializeArray()

Instead of

JavaScript
$("#INVOpeningStock_Form").serializeArray() 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900