C#: error Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory

ถ้าต้องการเขียน API App ผสมกับ View MVC HTML พวกนี้ปกติจะมี Error แบบ
Message=No service for type ‘Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory‘ has been registered. แก้ได้โดย

เปิดไฟล์ Program.cs ค้นหาบรรทัด
builder.Services.AddControllers();
แล้ว แก้เป็น
//builder.Services.AddControllers();
builder.Services.AddControllersWithViews();

เท่านี้ก็แก้ error ITempDataDictionaryFactory ได้แล้ว

อ่านเพิ่มเติม

Plus emotional magic to the knowledge of logic.

Exit mobile version