Saturday, 15 May 2010

asp.net mvc - Submitting form with Html.ActionLink submit inside an Ajax Form -



asp.net mvc - Submitting form with Html.ActionLink submit inside an Ajax Form -

i have ajax.beginform() form , want submit html post final post. here's form

@using (ajax.beginform("createset", "workout", new ajaxoptions { insertionmode = insertionmode.replace, updatetargetid = "divs", httpmethod = "post"}, new { id = "myform" })) { <div id="divs"> @html.partial("workoutset", session["workoutsetlist"]) </div> @html.actionlink("submit", "saveplan", "workout", new { type = "submit" }); //<input type="submit" value="submit" id="submit" name="command" /> <input type="submit" value="create set" name="command" /> }

basically "create set" button used lot ajax calls working fine. i'm able bind model rendered partial view , update model session on every ajax call.

for final step, want submit whole form saveplan action along model values , redirect home page after that.

problems faced:

first tried ajax submit button(the code commented out), script redirects saveplan along model values rendered partialview. problem not redirect homepage , i've read redirection cannot done on ajax call.

second, i've tried @html.actionlink goes saveplan action , proceeds redirect homepage, model values never passed. i've tried formcollection values don't passed either.

please provide advise on how solve this? i've spent 2 days on , i'm tearing myself on it.

to recap:

trying ajax way allows me pass model values not redirect home page trying html way doesn't allow me pass model values redirect home page.

you can redirect ajax post - in controller, need homecoming window.location javascript snippet:

return javascript(string.format("window.location = '{0}'", url.action("index")));

there article here: breaking out of ajax post

asp.net-mvc razor asp.net-ajax

No comments:

Post a Comment