GetNormalizedRouteValue

GetNormalizedRouteValue

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'的定义,找不到可以接受的扩展方法'GetNormalizedRouteValue'接受类型为'ActionContext'的第一个参数(是否缺少using指令或程序集引用?)

最佳答案

GetNormalizedRouteValue()方法是static,并且在Microsoft.AspNetCore.Mvc.Internal.NormalizedRouteValue类型上定义。

尝试以下方法:

var controllerName = NormalizedRouteValue.GetNormalizedRouteValue(context, CONTROLLER_KEY);


MSDN

关于c# - 如何在.Net Core 2.2中解析Microsoft.AspNetCore.Mvc.Internal.ActionContext.GetNormalizedRouteValue,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56445031/

10-10 21:56