MVC 3 Area route not working

前端 未结 8 803
有刺的猬
有刺的猬 2020-12-17 18:54

I created a Area in my MVC 3 application called \'Blog\'.

In global.asax I have the following code.

public static void RegisterRoutes(RouteCollection         


        
8条回答
  •  北荒
    北荒 (楼主)
    2020-12-17 19:25

    I had the same issue as Mindstorm Interactive, and took a slightly different approach. Yes, it does redirect the user, but it made my code look less workaroundy so to speak.

    I created a new controller, no matter in what area, since the problem is within the renderer not finding the view, not the controller.

    The controller then redirects with the area (as in Mindstroms fix, the key) included, and voila.

    public class StartController : Controller
    {
      public ActionResult Index()
      {
        return RedirectToAction("Index", "MyController", new { area = "MyArea" });
      }
    }
    

    in the RouteConfig just add

    routes.MapRoute(name: "Root", url: "", defaults: new { controller = "Start", action = "Index", area = "MyArea" });
    

    Hope it helps someone.

提交回复
热议问题