forum

Home / DeveloperSection / Forums / Redirecting when the querystring is empty

Redirecting when the querystring is empty

Anonymous User 1757 01-Jun-2015

In my sample I have two controllers for a bus service the bus routes and bus route stops. if a route hasn't been selected I need to redirect back to the bus route index. I

When I go directly to the bus route stop controller it should throw me back to the bus route list but it doesn't. 

public ActionResult Index()
        {
            string busRouteCode = "";
            //checks query string to see if empty
            if (Request.QueryString == null)
            {
                //checks the cookies to see if empty
                if (Request.Cookies["busRouteCode"] == null)
                    {
                    //if empty returns to bus route controller.
                     return View("index", "snBusRoutes");
                    }
                else
                    {
                        busRouteCode = Response.Cookies["busRouteCode"].Value;   
                    }                            
            }
            else
            {
              busRouteCode = Request.QueryString["busRouteCode"]; 
            }
            var routeStops = db.routeStops.Include(r => r.busRoute).Include(r => r.busStop);
            return View(routeStops.ToList());
        }


Updated on 01-Jun-2015
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By