Newbie Newbie - 1 year ago 86
C# Question

Building A Query String For Redirect

I am new to programming. I am trying to build up a query string to redirect to another action.

Here is the Action I am trying to redirect to

public ActionResult Rate(int Wid, int Uid)

Here is the action I am trying to redirect from

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

Answer Source

The query string parameters aren't part of the action name, but rather are values to be added to the URL. RedirectToAction has an overload which accepts an object of such parameters, which the framework will use to build the URL:

return RedirectToAction("Rate", new { Wid = Wid, Uid = Uid });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download