Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
44
rated 0 times [  47] [ 3]  / answers: 1 / hits: 26453  / 9 Years ago, mon, april 13, 2015, 12:00:00

I want to pass multiple parameters from Url.Action, Here is code in view



 window.location.href = @Url.Action(ABC, XYZ, new { @A= ViewBag.A , @B =  ViewBag.B });


And this is my Method in Controller XYZ



 public ActionResult ABC(string A, string B)
{
// Some Code
}


I always get values in first parameter only and 2nd one is always null. Either if I but B first. 2nd one is always null.
VIEW is basically under JavaScript function.
Here is the URL: http://localhost/CargoMainSite/XYZ/ABC?A=1&B=2
Please note there is some extra text between Parameter one and Parameter two, that is amp; if I explicitly removes it. It works fine and get proper values.


More From » asp.net-mvc

 Answers
15

Reason why Url.Action not working is that the & char in url is encoded, so you must use @Html.Raw as below



 window.location.href = @Html.Raw(@Url.Action(ABC, XYZ, new { @A= ViewBag.A , @B =  ViewBag.B }));

[#67092] Friday, April 10, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zachary

Total Points: 175
Total Questions: 89
Total Answers: 108

Location: Fiji
Member since Wed, Jul 14, 2021
3 Years ago
zachary questions
;