开发者

Creating links to current controller in a Partial view

I have a partial view that renders a paging control that is reused across several views and actions. But I can't work out how to generate a URL for my current action just appending a page number without knowing the action and controller I came from in the partial view.

Can 开发者_开发百科you get this information in a partial view?


You could fetch the current controller and action from the route data:

<%= Html.ActionLink(
    "link text",
    ViewContext.RouteData.GetRequiredString("action"),
    ViewContext.RouteData.GetRequiredString("controller"),
    new { page = "123" },
    null
) %>


You would need to pass that information into the into the ViewData for the paging control. Look at the overloads for RenderPartial to pass additional view data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜