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?
You can pass parameters to Web API controller methods using either the [FromBody] or the [FromUri] attributes. Note that the [FromBody] attribute can be used only once in the parameter list of a method.
Yes, it's possible. Just make sure your views have same view model. From a technical stand point, views don't have to have the same view model implemented within the same action. There's just as long as the controller passes in the expected type.
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}));
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With