Is there an ASP.NET MVC HtmlHelper for image links?

前端 未结 8 2290
误落风尘
误落风尘 2020-12-01 08:42

The Html.RouteLink() HtmlHelper works great for text links. But what\'s the best way to link an image?

8条回答
  •  独厮守ぢ
    2020-12-01 09:06

    I don't have enough SO swagger to add a comment, but this is a comment on MiniScalope's comment above:

    UrlHelper urlHelper = ((Controller)htmlHelper.ViewContext.Controller).Url;

    I would suggest making this an HtmlHelper extension method in itself (and simplify it), for reuse:

    private static UrlHelper Url(this HtmlHelper helper)
    { 
      return new UrlHelper(helper.ViewContext.RequestContext);
    }
    

提交回复
热议问题