No service for type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory' has been registered

前端 未结 11 777
终归单人心
终归单人心 2021-01-01 08:57

I\'m having this problem: No service for type \'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory\' has been registered. In asp.net core 1.0,

相关标签:
11条回答
  • 2021-01-01 09:03

    For .NET Core 2.0, in ConfigureServices, use :

    services.AddNodeServices();
    
    0 讨论(0)
  • 2021-01-01 09:04

    This one works for my case :

    services.AddMvcCore()
    .AddApiExplorer();
    
    0 讨论(0)
  • 2021-01-01 09:05

    Right now i has same problem, I was using AddMcvCore like you. I found error self descriptive, as an assumption I added AddControllersWithViews service to ConfigureServices function and it fixed problem for me. (I still use AddMvcCore as well.)

        public void ConfigureServices(IServiceCollection services)
        {
            //...
            services.AddControllers();
            services.AddControllersWithViews();
            services.AddMvcCore();
            //...
        }    
    
    0 讨论(0)
  • 2021-01-01 09:12

    Just add following code and it should work:

       public void ConfigureServices(IServiceCollection services)
            {
                services.AddMvcCore()
                        .AddViews();
    
            }
    
    0 讨论(0)
  • 2021-01-01 09:15

    I know this is an old post but it was my top Google result when running into this after migrating an MVC project to .NET Core 3.0. Making my Startup.cs look like this fixed it for me:

    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
        }
    
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
    
            app.UseRouting();
    
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
    
    0 讨论(0)
  • 2021-01-01 09:15

    You use this in startup.cs

    services.AddSingleton<PartialViewResultExecutor>();
    
    0 讨论(0)
提交回复
热议问题