小编Kai*_*ite的帖子

IRazorViewEngine.FindView 与 GetView 找不到视图

在我的 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)

_viewEngineIRazorViewEngine但没有找到任何。

我的项目结构:

项目结构

IView.FindView方法是从 Business …

razorengine asp.net-core-mvc asp.net-core

5
推荐指数
1
解决办法
4302
查看次数

如何在不使用内联映射或多个 .ForMember 的情况下在 automapper 中映射嵌套对象?

有一个问题,它非常精确地描述了我想要得到的内容,但他们使用的是内联映射。

源/目标类型

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)

c# automapper

4
推荐指数
1
解决办法
530
查看次数