javascript - Send two forms with one button and than redirect to third action -


is possible submit simultaneously 2 forms different actions? in actions want set tempdata , redirect third action.

i tried method described here submit 2 forms 1 button let's suggest each form have 1 input field. first form "name" input, second "lastname" input

    submitforms = function(){         document.forms["formforfirstaction"].submit();         document.forms["formforsecondaction"].submit();         window.location("/home/thirdaction")     } 

my actions looks like...

    [httppost]             public void firstaction(string name) {         tempdata["name"] = name;     }     [httppost]     public void secondaction(string lastname) {         tempdata["lastname"]=lastname;     }     public actionresult thirdaction () {         string fullname;         fullname = string.format((string)tempdata["name"] +          (string)tempdata["lastname"]);         return view(fullname);      } 

but doesn't work. in cases got name or last name in fullname string. looks it's async or other things don't know now. can please me?

tempdata available next immediate request. reason getting 1 item (the last 1 set 1 of 2 action methods) temp data dictionary. should consider using persistence mechanism session /database

also, instead of submitting form, oshould consider ajax

submitforms = function(){    $.post("@url.action("firstaction")",$("#formforfirstaction").serialize());    $.post("@url.action("secondaction")",$("#formforsecondaction").serialize());    window.location("/home/thirdaction") } 

and here example using session persist data

[httppost] public void secondaction(string lastname) {     session["lastname"]=lastname; } public actionresult thirdaction () {     string fullname;     fullname = string.format((string)session["name"] +      (string)session["lastname"]);     return view(fullname); } 

you may consider using jquery when() or q.all make sure redirecting after ajax call's done ( to avoid callback hell)


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -