c# - What is the difference between return View(model) and return RedirectToAction("ViewName",model) -
i can't index() action pass valid model review() action
... actionresult index()...
else { return redirecttoaction("review", wizard); <--wizard valid object here.... }
actionresult review()
public actionresult review() { return view(_wizard); <-- null. }
update: here whole controller. want take user wizard index, review page, transmit page saves data. i'm having real problems wrapping head around final piece. when used asp classic have explicitly write scratch, it's kind of hard used magic inherit in mvc3. so, bet i'm writing lot of uneeded code.
using system; using system.collections.generic; using system.linq; using system.web; using mvc3test.models; using microsoft.web.mvc; using system.web.mvc; using mvc3test.services; namespace mvc3test.controllers { public class wizardcontroller : controller { private wizardviewmodel wizard = new wizardviewmodel(); private dr405dbcontext db; public wizardcontroller(idbcontext dbcontext) { db = (dr405dbcontext)dbcontext; } public wizardcontroller() { db = new dr405dbcontext(); } public actionresult index() { wizard.initialize(); return view(wizard); } [httppost] public actionresult index([deserialize] wizardviewmodel wizard, istepviewmodel step) { wizard.steps[wizard.currentstepindex] = step; if (modelstate.isvalid) { if (!string.isnullorempty(request["next"])) { wizard.currentstepindex++; } else if (!string.isnullorempty(request["prev"])) { wizard.currentstepindex--; } else { return view("review", wizard); } } else if (!string.isnullorempty(request["prev"])) { wizard.currentstepindex--; } return view(wizard); } [allowanonymous] public actionresult review(wizardviewmodel model) { return view(model); } [allowanonymous] [httpget] public actionresult review(int32 id) { var service = new dr405service(db); var mywizard = service.wireupdatamodeltoviewmodel(service.dbcontext.dr405s.single(p => p.id == id)); return view(mywizard); } public actionresult transmit() { var service = new dr405service(db); service.wizard = wizard; service.save(); return view(); } } }
per msdn redirecttoaction
cause request review
action.
returns http 302 response browser, causes browser make request specified action.
this causes wizard
object loose value , needs repopulated.
view()
returns view associated action within current context.
you either place wizard in tempdata
, return view("review", wizard)
, or have wizard
passed route values if possible.
Comments
Post a Comment