在我的 asp.net core 项目中,我尝试使用以下方法查找 Razor 视图:
private IView FindView(ActionContext actionContext, string viewName)
{
var getViewResult = _viewEngine.GetView(executingFilePath: null, viewPath: viewName, isMainPage: true);
if (getViewResult.Success)
{
return getViewResult.View;
}
var findViewResult = _viewEngine.FindView(actionContext, viewName, isMainPage: true);
if (findViewResult.Success)
{
return findViewResult.View;
}
var searchedLocations = getViewResult.SearchedLocations.Concat(findViewResult.SearchedLocations);
var errorMessage = string.Join(
Environment.NewLine,
new[] { $"Unable to find view '{viewName}'. The following locations were searched:" }.Concat(searchedLocations));
throw new InvalidOperationException(errorMessage);
}
Run Code Online (Sandbox Code Playgroud)
在哪里
viewName = "Views/Email/ResetPassword.cshtml"
Run Code Online (Sandbox Code Playgroud)
是_viewEngine,IRazorViewEngine但没有找到任何。
我的项目结构:
IView.FindView方法是从 Business …
有一个问题,它非常精确地描述了我想要得到的内容,但他们使用的是内联映射。
public class SrcInner
{
public int A {get;set;} // imagine here 100500 properties
}
public class SrcOuter
{
public int B {get;set;}
public SrcInner C {get;set}
}
public class Dest
{
public int A {get;set;} // so here imagine 100500 same properties, as in SrcInner
public int B {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
public static void AddMapper(this IServiceCollection services)
{
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<SrcInner, Dest>();
cfg.CreateMap<SrcOuter, Dest>();
});
var mapper = config.CreateMapper();
services.AddSingleton(mapper);
} …Run Code Online (Sandbox Code Playgroud)