请求的服务“Microsoft.AspNetCore.Mvc.ViewFeatures”。尚未注册ITempDataDictionaryFactory。(学习笔记)

请求的服务“Microsoft.AspNetCore.Mvc.ViewFeatures”。尚未注册ITempDataDictionaryFactory。

  • .net5程序启动异常
    • 解决方案
    • 参考

.net5程序启动异常

The requested service 'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
**报错是因为没有注册:ITempDataDictionaryFactory,说白了就是没有注册mvc架构**

解决方案

  1. 修改 Startup.cs 中的 ConfigureServices方法
public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
}
  1. 修改 Startup.cs 中的 ConfigureServices方法
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddControllersWithViews();
 }

参考

https://www.cnblogs.com/ansheng/p/14239237.html

你可能感兴趣的:(C#,mvc,microsoft,学习)