来自Html助手扩展的Url.RouteUrl

时间:2011-04-08 15:59:07

标签: c# asp.net-mvc

我正在扩展Html.HtmlHelper以根据我的页面呈现面包屑:

public static HtmlString RenderBreadCrumb(this HtmlHelper helper, PageType pagetype, object Model)

如何在HtmlHelper中使用Url.RouteUrl来呈现URL?

1 个答案:

答案 0 :(得分:10)

您需要使用请求上下文创建新的UrlHelper实例。

UrlHelper Url = new UrlHelper(helper.ViewContext.RequestContext);
Url.RouteUrl(…);