2016-11-16 131 views
2

我是編程新手。我試圖建立一個查詢字符串重定向到另一個動作。構建重定向查詢字符串

這裏是我試圖重定向到

public ActionResult Rate(int Wid, int Uid) 
{ 
} 

這裏的動作是我想從

public ActionResult ConfirmHire2(bool userConfirmed, int confirId) 
{ 
    int Wid = cm.GetCleanerIdFromSale(confirId); 
    int Uid = um.GetUserIdFromSale(confirId); 
    //I need something to this affect but it is not working 
    //return RedirectToAction("'Rate?Wid=' + Wid + 'Uid=' + Uid"); 
} 

回答

3

重定向操作的查詢字符串參數不動作的一部分名稱,而是要添加到URL中的值。 RedirectToActionan overload它接受這樣的參數的對象,該框架將用於建立的網址:

return RedirectToAction("Rate", new { Wid = Wid, Uid = Uid }); 
+0

非常有趣!非常感謝您花時間回答我! – Newbie

0

試試這個:

return RedirectToAction("Rate", new { Wid = Wid, Uid = Uid }); 
0

您可以通過ID作爲routeValues參數的一部分:

return RedirectToAction("Rate", new { Wid = 123, Uid = 123 }); 
0
public ActionResult ConfirmHire2 (bool userConfirmed, int confirId) 
{ 
    int Wid = cm.GetCleanerIdFromSale(confirId); 
    int Uid = um.GetUserIdFromSale(confirId); 
    // Use C#6 `nameof` API for compile time validation of your `RedirectToAction` call 
    return RedirectToAction(nameof(Rate), new { Wid = Wid, Uid = Uid }); 
} 

public ActionResult Rate(int Wid, int Uid) 
{ 
}