skip to Main Content

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?

enter image description here

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


  1. I also got this error before. When I swapped the MapAreaControllerRoute definition to the top, I was able to access my area.

    Login or Signup to reply.
  2. Add Area route

    Area routes typically use conventional routing rather than attribute
    routing. Conventional routing is order-dependent. In general, routes
    with areas should be placed earlier in the route table as they’re more
    specific than routes without an area.

    {area:…} can be used as a token in route templates if url space is
    uniform across all areas:

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search