2013-05-09 31 views
6

Başka bir eylem için bir dize ve model (nesne) göndermek istiyorum. Ben nesneleri hSm özelliğini ayarlayın rağmen model ve parametreyi RedirectToAction ile iletme

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

Ben, bu null nesne gönderir new anahtar kelime kullanın.

Bu benim Search eylemdir:

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

cevap

13

Bir RedirectAction ile veri gönderemez. Çünkü bir 301 yönlendirme yapıyorsunuz ve bu da istemciye geri gidiyor.

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

Bundan sonra TempData tekrar alabilirsiniz:

public ActionResult Search(string culture, HotelSearchModel hotelSearchModel) 
{ 
    var obj = TempData["myObj"]; 
    hotelSearchModel = obj.hotelSearchModel; 
    culture = obj.culture; 
} 
Eğer gerekenler

TempData kaydetmek olduğunu

İlgili konular