I want to pass multiple parameters from Url.Action, Here is code in view
我想从Url.Action传递多个参数,这是代码中的代码
window.location.href = "@Url.Action("ABC", "XYZ", new { @A= ViewBag.A , @B = ViewBag.B })";
And this is my Method in Controller XYZ
这是我在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.
我总是只在第一个参数中获取值,第二个参数始终为null。要么我,要么B先。第二个总是空的。 VIEW基本上属于JavaScript功能。这是URL:http:// localhost / CargoMainSite / XYZ / ABC?A = 1& B = 2请注意参数1和参数2之间有一些额外的文本,即“amp;”如果我明确删除它。它工作正常,并获得适当的价值。
1 个解决方案
#1
17
Reason why Url.Action not working is that the & char in url is encoded, so you must use @Html.Raw as below
Url.Action无效的原因是url中的&char已编码,因此您必须使用@ Html.Raw,如下所示
window.location.href = "@Html.Raw(@Url.Action("ABC", "XYZ", new { @A= ViewBag.A , @B = ViewBag.B }))";
#1
17
Reason why Url.Action not working is that the & char in url is encoded, so you must use @Html.Raw as below
Url.Action无效的原因是url中的&char已编码,因此您必须使用@ Html.Raw,如下所示
window.location.href = "@Html.Raw(@Url.Action("ABC", "XYZ", new { @A= ViewBag.A , @B = ViewBag.B }))";