asp.net-mvc 如何在 Url.Action 中发送多个参数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24178320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you send multiple parameters in a Url.Action?
提问by Vinit Patel
How do you send multiple parameters in an Url.Action?
你如何在一个中发送多个参数Url.Action?
I have a controller with an action, and I want 2 parameters, but the 2nd parameter is not being received.
我有一个带动作的控制器,我想要 2 个参数,但没有收到第二个参数。
My code is:
我的代码是:
@Url.Action("Products", "Jquery", new { categoryid = 1, Productid = 2})
Publc Action Jquery(int categoryid ,int Productid)
{
}
but I only receive categoryid, every time Productidis null.
但我只收到categoryid,每次Productid都是空的。
Please suggest to me what to do?
请建议我该怎么做?
采纳答案by rob waminal
try it like this.
像这样试试。
@Url.Action("Jquery", "Products", new { @categoryid = 1, @Productid = 2})
public ActionResult Jquery(int categoryid, int Productid)
{
return View();
}
you should get the 2 parameters in your action. Assuming the JqueryAction is under ProductController
您应该在操作中获得 2 个参数。假设Jquery行动是在ProductController
回答by d219
Were you calling this action from JQuery? Sounds like you could be from the symptoms (or at least @roberto could be); if so wrap it in Html.Raw:
你是从 JQuery 调用这个动作的吗?听起来您可能来自症状(或者至少@roberto 可能是);如果是这样的话Html.Raw:
@Html.Raw(@Url.Action("Jquery", "Products", new { @categoryid = 1, @Productid = 2}));
回答by LuisEduardoSP
I had the same problem, added the @'s and didn't work.
我遇到了同样的问题,添加了@,但没有用。
What worked for me was the @Html.Rawinstruction.
对我有用的是@Html.Raw指令。
@Html.Raw(@Url.Action("Jquery", "Products", new { categoryid = 1, Productid = 2}))
public ActionResult Jquery(int categoryid, int Productid)
{
return View();
}
In this way you can get all parameters in the controller, not only the first.
通过这种方式,您可以获取控制器中的所有参数,而不仅仅是第一个。

