What is the difference between these two ways of passing
arguments to an Action?
(1) @Url.Action("MyAction",
"MyController")?arg1=5&arg2="hello";
(2) @Url.Action("MyAction", "MyController", new {arg1=5, arg2="hello"});
Home / DeveloperSection / Forums / Passing arguments to Url.Action
What is the difference between these two ways of passing
arguments to an Action?
(1) @Url.Action("MyAction",
"MyController")?arg1=5&arg2="hello";
(2) @Url.Action("MyAction", "MyController", new {arg1=5, arg2="hello"});
Pravesh Singh
27-Nov-2014The difference is whether you're taking ASP.Net Routing into account.
Assuming you have a route defined as follows:
Your 1st call would generate the following URL:
/CallMyAction?arg1=5&arg2=hello
While the 2nd call would generate a URL that is adhering the route pattern you defined:
/CallMyAction/5-hello