有一个这样的帮助方法:
public static IHtmlContent Source(this IHtmlHelper html, string s)
{
var path = ServerMapPath() + "Views\\" + s;
Run Code Online (Sandbox Code Playgroud)
我需要在asp.net核心中获得相当于Server.MapPath的功能
你需要注射IHostingEnvironment.然后:
var path = env.ContentRootPath + "Views\\" + s;
在一个html帮助器中,你可以这样做:
((IHostingEnvironment)html.ViewContext.HttpContext.RequestServices.GetService(typeof(IHostingEnvironment))).ContentRootPath;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10487 次 |
| 最近记录: |