c# - How to reload page with previously entered parameters? -


i working on code project in asp.net mvc. have issue redirecting user after have completed action. have these controllers:

index search page:

public actionresult index(){      //this method sets viewmodel data search preferences      viewmodel obj = new viewmodel();     //set values of dropdowns , searching capabilities     return view("search", obj); } 

the user fills out search boxes in view, chooses dropdowns. return post search method handles data:

[httppost] public actionresult index(viewmodel obj, int? page) {     data = in db.database            select i;      if(!string.isnullorempty(obj.example)     {         data = data.where(x => x.poss == obj.poss);     }      //paging , other data formatting here      return view("results", data); } 

once result list displayed, have checkbox/button system in result view allows user select multiple results , mark them "good", "bad" etc. method changes database simply. problem after database alters data, im not sure how return user exact result set at. method returns void doesn't work, , parameters not separated, (one whole viewmodel), can't save url , return them unique url. want keep viewmodel parameter. how can save viewmodel data contains search preferences use later page number without changing method this:

[httppost] public actionresult index(string dropdown1, string dropdown2, int num......){} 

one thing did save view model session. deserialize in index method. in index method:

[httpget] public actionresult advancedsearch() {          httpcontext currentcontext = system.web.httpcontext.current;         advancedsearchviewmodel advancedsearchviewmodel = (advancedsearchviewmodel)session["advancedsearchviewmodel"];         if (advancedsearchviewmodel == null)         {             advancedsearchviewmodel = new advancedsearchviewmodel();             addadvancedsearchlists(advancedsearchviewmodel, currentcontext);         }          return view(advancedsearchviewmodel);      } 

here code save session in post:

session["advancedsearchviewmodel"] = advancedsearchviewmodel; 

note if have listboxes (drop down , multi select) have rebuild listboxes in post method , reselect selections (for multi select). html stateless. mvc not send listbox contents server on post, sends selected.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -