I got this error when creating ASP.net core MVC 8 application:
InvalidOperationException: The view 'Edit' was not found. The following locations were searched: /Views/Category/Edit.cshtml /Views/Shared/Edit.cshtml
To solve this, I added: builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
I never use this service when creating scaffolding.
-
Controllers/CategoryController.cs:
// GET: Category/Edit/5public IActionResult Edit(int? id) { if (id == null) { return NotFound(); } Category? category = _db.Categories.Find(id); if (category == null) { return NotFound(); } return View(category); }
-
Views/Category/Edit.cshtml:
@model Category @{ ViewData["Title"] = "Edit"; } <h1>Edit</h1>
Can any experts help explain? Is there a way to avoid using the service mentioned above?
Thanks.