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个参数,但没有收到第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 Productid
is null.
但每次Productid为null时,我只会收到categoryid。
Please suggest to me what to do?
请告诉我该怎么办?
3 个解决方案
#1
8
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 Jquery
Action is under ProductController
你应该在你的行动中获得2个参数。假设Jquery Action在ProductController下
#2
9
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}));
#3
0
I had the same problem, added the @'s and didn't work.
我遇到了同样的问题,添加了@并且没有用。
What worked for me was the @Html.Raw
instruction.
对我有用的是@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.
通过这种方式,您可以获得控制器中的所有参数,而不仅仅是第一个参数。
#1
8
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 Jquery
Action is under ProductController
你应该在你的行动中获得2个参数。假设Jquery Action在ProductController下
#2
9
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}));
#3
0
I had the same problem, added the @'s and didn't work.
我遇到了同样的问题,添加了@并且没有用。
What worked for me was the @Html.Raw
instruction.
对我有用的是@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.
通过这种方式,您可以获得控制器中的所有参数,而不仅仅是第一个参数。