2013-05-09 4 views
6

문자열과 모델 (객체)을 다른 작업으로 보내려고합니다. 나는 물체를 hSm 속성을 설정하지만 RedirectToAction을 통한 모델 및 매개 변수 전달

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 }); 

나는 그것이 null 객체를 전송 new 키워드를 사용하는 경우.

이 내 Search 작업입니다 :

public ActionResult Search(string culture, HotelSearchModel hotelSearchModel) 
{ 
    // ... 
} 

답변

13

당신은 RedirectAction 데이터를 보낼 수 없습니다. 301 리디렉션을 수행 중이며 클라이언트로 돌아 가기 때문입니다.

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"); 

를 그 후에는 TempData에서 다시 검색 할 수 있습니다 :

public ActionResult Search(string culture, HotelSearchModel hotelSearchModel) 
{ 
    var obj = TempData["myObj"]; 
    hotelSearchModel = obj.hotelSearchModel; 
    culture = obj.culture; 
} 
당신이 필요가있는 무엇

은 TempData에 저장입니다