asp.net mvc 3 - Pass an object while submitting a form in Javascript -



asp.net mvc 3 - Pass an object while submitting a form in Javascript -

i have in controller.

public actionresult getresult(employee employee){ homecoming redirecttoaction("index","employee"); }

i cannot utilize ajax phone call because post , wait response, not submit.

when have this, works.

[httppost] public actionresult getresult(string firstname,string lastname){ homecoming redirecttoaction("index","employee"); } in javascript var form = $("#employee); form.attr('action','employee/index?firstname='tim'&lastname='tom'); form.submit();

the above works when passing parameters querystring.but don't know how pass object while doing post. tried using $.post. did not work.

thanks.

jquery post in mvc works way:

since controller action method is:

public actionresult getresult(employee employee) { homecoming redirecttoaction("index","employee"); }

you might want modify jquery post phone call way

var postdata=function() { //prepare javascript object var employee= { firstname:"firstname", lastname:"lastname" }; $.post('/getresult',employee,function(data){ //process info here using the info nowadays in info obj }); }

model binder in mvc checks same paramters in javascript object model have & , should match parameter name of action method javascript object name.

let me know if works out you.

thanks

javascript asp.net-mvc-3 form-submit

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -