passing model and parameter with RedirectToAction
17,774
You can't send data with a RedirectAction
.
That's because you're doing a 301
redirection and that goes back to the client.
What you need to is save it 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 that you can retrieve again from the TempData:
public ActionResult Search(string culture, HotelSearchModel hotelSearchModel)
{
var obj = TempData["myObj"];
hotelSearchModel = obj.hotelSearchModel;
culture = obj.culture;
}
Author by
user1688401
Updated on June 12, 2022Comments
-
user1688401 almost 2 years
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 sendsnull
object, although I set the objectshSm
property.This is my
Search
action :public ActionResult Search(string culture, HotelSearchModel hotelSearchModel) { // ... }