Specify QueryString in Html.Action

2019-08-14 04:46发布

问题:

0I want to insert the output of an action into a view. The problem is that the action requires some info in the querystring. Is there a way to include the querystring params in Action?

Example:

@Html.Action("Get","Contacts")

To get the proper result back, I need to pass ?pagenum=1 to the action.

@Html.Action("Get?pagenum=1","Contacts")  unfortunately doesn't work

回答1:

@Html.Action("YourActionName", "YourControllerName", new { pagenum = 1 })

Use the overload of Action() to define route values.

MSDN Reference

Is your Action Method really named Get()? If so, and your controller name is Contacts, your modified code would need to be:

@Html.Action("Get", "Contacts", new { pagenum = 1 })