Url.RouteUrl from Html Helper Extension

I am extending Html.HtmlHelper to display a palette depending on the page:

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

How to use Url.RouteUrl inside an HtmlHelper to display a URL?

+6
source share
2 answers

You need to create a new UrlHelper instance using the request context.

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

Just create the UrlHelper extension:

 public static string RenderBreadCrumb(this UrlHelper helper, PageType pagetype, object Model) 

Then call through:

  @Url.RenderBreadCrumb(pageType, Model) 
+1
source

Source: https://habr.com/ru/post/885522/


All Articles