.net Core2.2にカスタムRazorViewEngineを実装しています。
MSDNによると、このGetNormalizedRouteValue()
メソッドはMicrosoft.AspNetCore.Mvc.Internal for .Net Core 2.2内に存在しますが、アセンブリをコンパイルまたは検査すると、存在しないように見えます。
私が使用している私のコードコンテキストはそれを使用しています 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);
}
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のドキュメントを確認しましたが、存在するはずです。
「ActionContext」には「GetNormalizedRouteValue」の定義が含まれておらず、「ActionContext」タイプの最初の引数を受け入れるアクセス可能な拡張メソッド「GetNormalizedRouteValue」が見つかりませんでした(usingディレクティブまたはアセンブリ参照がありませんか?)
GetNormalizedRouteValue()
方法は、static
上に定義されているMicrosoft.AspNetCore.Mvc.Internal.NormalizedRouteValue
タイプ。
代わりにこれを試してください:
var controllerName = NormalizedRouteValue.GetNormalizedRouteValue(context, CONTROLLER_KEY);
MSDNを参照してください
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加