How do you send multiple parameters in a Url.Action?

有些话、适合烂在心里 提交于 2019-12-03 16:14:30

问题


How do you send multiple parameters in an Url.Action?

I have a controller with an action, and I want 2 parameters, but the 2nd parameter is not being received.

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.

Please suggest to me what to do?


回答1:


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:


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:

@Html.Raw(@Url.Action("Jquery", "Products", new { @categoryid = 1, @Productid = 2}));



回答3:


I had the same problem, added the @'s and didn't work.

What worked for me was the @Html.Raw instruction.

@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.



来源:https://stackoverflow.com/questions/24178320/how-do-you-send-multiple-parameters-in-a-url-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!