Passing multiple parameters to url in MVC 3

I have an action method in the controller called "Registration" as

public ActionResult Facility(int id = 0, int contractId = 0)

when i call this method from url like

/Registration/Facility/0?contractId=0

It works great. Now when I try to build above url in another method, for example

return RedirectToAction("Facility/0?contractId="+ model.ContractId);

it does not work, the URL in the browser is not built well, it comes as

/Registration/Facility/0%3fcontractId%3d0

Can someone please tell me what I'm doing wrong here?

+5
source share
3 answers

Try the following:

return RedirectToAction("Facility", new { id = 0, contractId = model.ContractId});

See this answer

+11
source

There is a built-in method overload for redirection. Pass an anonymous object with the values ​​you want

return RedirectToAction("Facility", new { id = 0, contractId = model.ContractId });
+1
source

, :

return RedirectToAction("Facility", new { contractId = model.ContractId });
0

All Articles