ASP.NET MVC Routing Question

前端 未结 6 2129
悲哀的现实
悲哀的现实 2021-02-02 17:08

I must be dense. After asking several questions on StackOverflow, I am still at a loss when it comes to grasping the new routing engine provided with ASP.NET MVC. I think I\'v

6条回答
  •  半阙折子戏
    2021-02-02 18:03

    You could handle that in the home controller, but the controller method would not be very elegant. I'm guessing something like this might work (not tested):

    routes.MapRoute(
        "Root",
        "{controller}/{view}",
        new { controller = "Home", action = "Index", view = "" }
    );
    

    Then in your HomeController:

    public ActionResult Index(string view) {
        switch (view) {
            case "":
                return View();
    
            case "register":
                return View("Register");
    
            default: 
                // load user profile view
        }
    }
    

提交回复
热议问题