0

My current website requires user to choose their restaurant type before accessing the sub menus.

For example, when users try to direct access to http://localhost:8888/Restaurant/KFCMenu/?id=KFCCurlyFries they will be redirected to this page http://localhost:8888/Restaurant/Home

The logic here I would like to mention is since they want to access to KFC Curly Fries menu (in the parameter), the route should auto assign the restaurant type based on the parameter and skip the Home controller/Index to choose.

May I know how can I write my custom route to bypass the Home controller/Index in this scenario?

This is my default routing in RouteConfig.cs

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "UserLogin", action = "Index", id = UrlParameter.Optional }
);

Updates:

My Restaurant controller

 public class RestaurantController: Controller
    {
        public ActionResult Index(HomeModel vm, string btnModeMcd, string btnModeKFC, string btnModePizzaHut, string Menu)
        {
            if (!string.IsNullOrWhiteSpace(Menu))
            {
                TempData["Success"] = "<script>Swal({" +
                            "title: 'Access Denied'," +
                            "text: 'Access Denied for " + Menu + " Menu'," +
                            "type: 'warning'," +
                            "timer: 2500," +
                            "confirmButtonColor: '#5cb85c'," +
                            "cancelButtonColor: '#3085d6'," +
                            "confirmButtonText: 'OK'," +
                            "cancelButtonText: 'New Menu'" +
                        "});</script>";
            }

            if (string.IsNullOrWhiteSpace((string)Session["MODE"]))
            {
                Session["MODE"] = "Mcd";
            } 

            if (btnModeMcd != null)
            {
                Session["MODE"] = "Mcd";
            }

            if (btnModeKFC != null)
            {
                Session["MODE"] = "KFC";
            }

            if (btnModePizzaHut != null)
            {
                Session["MODE"] = "PizzaHut";
            }
            
            vm.Mode = (string)Session["MODE"];
            return View(vm);
        }
        
        public ActionResult About()
        {
            ViewBag.Message = "Your description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        public ActionResult AccessDenied(string Menu)
        {
            TempData["Success"] = "<script>Swal({" +
                        "title: 'Access Denied'," +
                        "text: 'Access Denied for " + Menu + " Menu'," +
                        "type: 'warning'," +
                        "timer: 2500," +
                        "confirmButtonColor: '#5cb85c'," +
                        "cancelButtonColor: '#3085d6'," +
                        "confirmButtonText: 'OK'," +
                        "cancelButtonText: 'New Menu'" +
                    "});</script>";
            return View();
        }
    }
karl233
  • 1
  • 1
  • routes are defined as to what is available., not flow execution.... so i would say u are focusing on the wrong thing. – Seabizkit Oct 08 '20 at 08:46
  • @Seabizkit I see. Any suggestion on what way should I use to achieve my goal? – karl233 Oct 08 '20 at 08:53
  • Can you share relevant code of Restaurant controller? – Chetan Oct 08 '20 at 09:06
  • to be honest it hard to follow as your description of what needs to happen is hard to follow which is probably why ur struggling with what u are. Suggestion would be structure your q better so people can better understand. User is on page x and..... they get redirected why? well then they not really on x they now on y, and then... its confusing as the only way they get to those pages is if u redirected them... so why are you confused. Better to show more code with better described intentions. – Seabizkit Oct 08 '20 at 10:23
  • i think i follow now... you want to read the url to make assumption about the location..., well u need to code for this. read the url and make logic based on this. either pass the value around or store the values where which your happy with, pros and cons with all. session, cookie, local storage. how is ur other page setting it.... maybe use the same method. again im guessing what u trying to do.... but this is all stuff u need to code. – Seabizkit Oct 08 '20 at 10:26
  • @ChetanRanpariya Hi, I have added my restaurant controller code – karl233 Oct 09 '20 at 01:51
  • @Seabizkit The current structure is users have to choose the mode before entering sub menu. Since the user know he wants to access the PizzaHut menu (pass PizzaHut as parameter to set in the SESSION["MODE"]), I wonder why I still cannot skip the Restaurant page (main menu) – karl233 Oct 09 '20 at 01:53
  • @Seabizkit Yes, exactly. From the URL provided by user, I want to direct him to the sub menu page. The user now are complaining every time they access the sub menu, they have to choose the mode. Even the session mode can be known by looking at the sub menu URL – karl233 Oct 09 '20 at 01:57

1 Answers1

0

you have way to much going on and your not showing enough to actutal answer

//url: Restaurant/Index?menu="someValue"
public class RestaurantController: Controller
{
    //you need to be clear if this is a post or get..
    [HttGeet]
    public ActionResult Index(HomeModel vm, string menu)
    {
        //do check if menu is valid, return 404 if not
        Session["MODE"] = menu; //why not call this RestaurantName
        return View();
    }
}
        
//what is HomeModel
Seabizkit
  • 2,417
  • 2
  • 15
  • 32