[英]How to pass multiple parameters in Url.Action()
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.
要么我,要么B先。 2nd one is always null.
第二个总是空的。 VIEW is basically under JavaScript function.
VIEW基本上属于JavaScript功能。 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;" 这是URL:
http://localhost/CargoMainSite/XYZ/ABC?A=1&B=2
请注意参数1和参数2之间有一些额外的文本,即“amp;” if I explicitly removes it. 如果我明确删除它。 It works fine and get proper values.
它工作正常,并获得适当的价值。
Url.Action无效的原因是url中的&char已编码,因此您必须使用@ Html.Raw ,如下所示
window.location.href = "@Html.Raw(@Url.Action("ABC", "XYZ", new { @A= ViewBag.A , @B = ViewBag.B }))";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.