asp.net mvc - passing model and parameter with RedirectToAction -


i want send string , model (object) action.

var hsm = new hotelsearchmodel(); hsm.cityid = cityid; hsm.startat = startat; hsm.endat = endat; hsm.adultcount = adultcount; hsm.childcount = childcount;  return redirecttoaction("search", new { culture = culture, hotelsearchmodel = hsm }); 

when use new keyword sends null object, although set objects hsm property.

this search action :

public actionresult search(string culture, hotelsearchmodel hotelsearchmodel) {      // ... } 

you can't send data redirectaction. that's because you're doing 301 redirection , goes client.

what need save in tempdata:

var hsm = new hotelsearchmodel(); hsm.cityid = cityid; hsm.startat = startat; hsm.endat = endat; hsm.adultcount = adultcount; hsm.childcount=childcount; tempdata["myobj"] = new { culture = culture,hotelsearchmodel = hsm };  return redirecttoaction("search"); 

after can retrieve again tempdata:

public actionresult search(string culture, hotelsearchmodel hotelsearchmodel) {     var obj = tempdata["myobj"];     hotelsearchmodel = obj.hotelsearchmodel;     culture = obj.culture; } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -