I want to send a string and a model (object) to another 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 I use the new
keyword it sends null
object, although I set the objects hSm
property.
This is my Search
action :
public ActionResult Search(string culture, HotelSearchModel hotelSearchModel)
{
// ...
}
You can't send data with a
RedirectAction
. That's because you're doing a301
redirection and that goes back to the client.What you need to is save it in TempData:
After that you can retrieve again from the TempData: