我需要 html Helper 中的 url helper 所以我有
IHtmlHelper<T> html
并且需要得到 IUrlHelper
我试过这个:
html.ViewContext.HttpContext.RequestServices.GetService(typeof(IUrlHelper));
Run Code Online (Sandbox Code Playgroud)
但它返回空
在这里得到答案:https : //github.com/aspnet/Mvc/issues/5051 所以它看起来像这样:
public static IHtmlContent MyHelper(this IHtmlHelper<T> html){
var urlHelperFactory = (IUrlHelperFactory)html.ViewContext.HttpContext.RequestServices.GetService(typeof(IUrlHelperFactory));
var urlHelper = urlHelperFactory.GetUrlHelper(aweInfo.Html.ViewContext);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1111 次 |
| 最近记录: |