In ASP.NET MVC how can I use the Razor @Url.Content() helper from C# code?

前端 未结 6 1828
日久生厌
日久生厌 2020-12-03 04:07

I\'m trying to write a html helper extension that outputs an image tag. I need to access (within C# code) something like Razor\'s @Url.Content() helper to get the proper URL

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 04:53

    Something like this perhaps?

    public static string MyHelper(this HtmlHelper h)
    {
          string url = h.ViewContext.HttpContext.Request.Url.AbsoluteUri;
    }
    

提交回复
热议问题