Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass multiple parameters in Url.Action()

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.

like image 743
Affan Shahab Avatar asked Apr 13 '15 11:04

Affan Shahab


1 Answers

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 }))";
like image 135
Abbas Galiyakotwala Avatar answered Oct 18 '22 07:10

Abbas Galiyakotwala