【发布时间】:2019-06-04 13:33:48
【问题描述】:
Microsoft.AspNetCore.Mvc.Internal.ActionContext.GetNormalizedRouteValue() 不存在
我正在 .net Core 2.2 中实现自定义 Razor ViewEngine。
MSDN 声明 GetNormalizedRouteValue() 方法存在于 .Net Core 2.2 的 Microsoft.AspNetCore.Mvc.Internal 中,但在我编译或检查程序集时它似乎不存在。
我的代码
我使用它的代码上下文是context.GetNormalizedRouteValue(AREA_KEY)
public class CustomViewEngine : IViewEngine
{
public ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage)
{
var controllerName = context.GetNormalizedRouteValue(CONTROLLER_KEY);
var areaName = context.GetNormalizedRouteValue(AREA_KEY);
var checkedLocations = new List<string>();
foreach (var location in _options.ViewLocationFormats)
{
var view = string.Format(location, viewName, controllerName);
if (File.Exists(view))
{
return ViewEngineResult.Found("Default", new CustomView(view, _customViewRendering));
}
checkedLocations.Add(view);
}
return ViewEngineResult.NotFound(viewName, checkedLocations);
}
微软的 API
检查 Microsoft API 时,似乎只存在以下方法签名。
namespace Microsoft.AspNetCore.Mvc
{
public class ActionContext
{
public ActionContext();
public ActionContext(ActionContext actionContext);
public ActionContext(HttpContext httpContext, RouteData routeData, ActionDescriptor actionDescriptor);
public ActionContext(HttpContext httpContext, RouteData routeData, ActionDescriptor actionDescriptor, ModelStateDictionary modelState);
public ActionDescriptor ActionDescriptor { get; set; }
public HttpContext HttpContext { get; set; }
public ModelStateDictionary ModelState { get; }
public RouteData RouteData { get; set; }
}
}
我检查了MSDN's documentation,它表明它应该存在。
错误
“ActionContext”不包含“GetNormalizedRouteValue”的定义,并且找不到接受“ActionContext”类型的第一个参数的可访问扩展方法“GetNormalizedRouteValue”(您是否缺少 using 指令或程序集引用?)
【问题讨论】:
标签: c# .net-core asp.net-core-mvc