asp.net mvc - Multiple views modifying one object MVC -
i building service requires lengthy setup process. have broken 4 models , 4 corresponding views. setup, setup2, setup3, , setup4. each of these views gathers information user stored in user object. have been passing user along this:
[httppost] public actionresult setup(formcollection values) { user registeringuser = new user(); registeringuser.email = user.identity.name; registeringuser.fname = values["fname"]; registeringuser.lname = values["lname"]; registeringuser.phone = values["phone"]; return redirecttoaction("/setup2", registeringuser); }
for reason, seems work fine first jump (from setup setup2) after i'm getting weird behavior, such user. getting set null when user passed view.
in related, different issue, need last screen (setup4) recursive. screen adds course in user enrolled, , if don't check "this last class" button, needs clear form can enter course.
the entire controller looks this:
[httppost] public actionresult setup4(formcollection values, user registeringuser) { // values["allclassesadded"] returns "false" string if box unchecked, returns "true,false" if checked. // solution: parse string "true" if (utils.parsefortrue(values["allclassesadded"])) { // todo redirect "congratulations you're done" page. database.createuserindb(registeringuser); return redirect("/home"); } else { // build course , add list in user course c = new course(values); if (request.isauthenticated) { //registeringuser.currentcourses.add(c); registeringuser.addcourse(c); return redirecttoaction("/setup4", registeringuser); // <---- doesn't work right //return view(); } else { return redirect("/account/login"); } } }
this first project mvc, if find i'm doing entire thing incorrectly, feel free not answer question asked , offer proper solution need. i'm moving existing (pure) c# project mvc , i'm stuck on how work within mvc's interesting structure. i'm grateful can give!
thanks!
you can store user related data in session without passing between requests
smth this
[httppost] public actionresult step1(step1model model) { session["userregistration"] = new userregistration { firstname = model.fname, .... } .... } [httppost] public actionresult step2(step2model model) { var userregistration = session["userregistration"] userregistration; if (userregistration == null) { return redirrect("step1"); } userregistration.somefield = model.somefield; ... session["userregistration"] = userregistration; .... }
Comments
Post a Comment