asp.net mvc 3 - How do I get the value of a button to pass back to the server when using JQuery & AJAX? -


i using mvc3, razor, c#, jquery , ajax.

i using ajax call postback form server. form element values being passed controller in:

    [httppost]     public actionresult edit(product myproduct, string actiontype)      if (actiontype == "save")        save.... 

and in view have:

@using (html.beginform("edit", "ra", formmethod.post, new { @class = "editform", @id = "frmedit" })) 

form elements:

<td> @html.hiddenfor(p=>p.id)  <button type="submit" name="actiontype" value="save" >save</button> </td> <td>@html.editfor(p=>p.name)</td> 

some ajax:

    $('.editform').on('submit', function () {     $.ajax({         url: this.action,         type: this.method,         data: $('#frmedit').serialize(),                   context: $('button', this).closest('tr'),         success: function (result) {             $(this).html(result);         }     });     return false; }); 

now think problem line since have seen quite few posts problem jquery , submitting button values:

        data: $('#frmedit').serialize(),  

but cannot button submit actiontype of "save". null.

thoughts appreciated.

thanks.

update:

my code seems interfere jquery listener ?? code is:

<input type="submit" id="btn" name="btn" value="save" onclick="document.getelementbyid('actiontype').value = 'save';"/> 

from documentation:

no submit button value serialized since form not submitted using button.

however can add hand:

data: $('#frmedit').serialize() + '&actiontype=save', 

or

data: $('#frmedit').serialize()      + '&'     + encodeuricomponent(button.name)     + '='     + encodeuricomponent(button.value), 

where button <button> dom element.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -