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();
}
}