In Asp.net Core 5, my area is the same solution in a different project. I import the dlls with the application part, but. When I go to the index page in the area, it cannot find the view. It falls into the action in the controls, but cannot find the view. What can I do for solution?
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapAreaControllerRoute(
name: "default_area",
areaName:"Test",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
});
[Area("Test")]
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult Privacy()
{
return View();
}
public IActionResult Testtt()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
2
Answers
I also got this error before. When I swapped the MapAreaControllerRoute definition to the top, I was able to access my area.
This is from the documentation -> https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/areas?view=aspnetcore-6.0
So you should add your area routing before the default routing.