我是编程新手。我正在尝试构建一个查询字符串以重定向到另一个操作。
以下是我尝试重定向到
的操作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");
}
答案 0 :(得分:3)
查询字符串参数不是操作 name 的一部分,而是要添加到URL的值。 RedirectToAction
有an overload,它接受这些参数的对象,框架将用它来构建URL:
return RedirectToAction("Rate", new { Wid = Wid, Uid = Uid });
答案 1 :(得分:0)
试试这个:
return RedirectToAction("Rate", new { Wid = Wid, Uid = Uid });
答案 2 :(得分:0)
您可以将id作为routeValues参数的一部分传递:
return RedirectToAction("Rate", new { Wid = 123, Uid = 123 });
答案 3 :(得分: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)
{
}