title: How to add QueryString in OnActionExecuting()?
body: <p>i want to add two queryString in current request URL if it is not exsist</p>
  
  <p><strong>Edited:</strong></p>
  
  <p>I tried this ---</p>
  
  <pre><code>public override void OnActionExecuting(ActionExecutingContext filterContext)
  {
  if (filterContext.RequestContext.HttpContext.Request.QueryString["mid"] == null &amp;&amp; filterContext.RequestContext.HttpContext.Request.QueryString["mod"] == null)
  {
  mid = Convert.ToString(HttpUtility.ParseQueryString(filterContext.RequestContext.HttpContext.Request.UrlReferrer.Query)["mid"]);
  mod = Convert.ToString(HttpUtility.ParseQueryString(filterContext.RequestContext.HttpContext.Request.UrlReferrer.Query)["mod"]);
  if (!string.IsNullOrEmpty(mid) || !string.IsNullOrEmpty(mod))
  {
  RouteValueDictionary redirecttargetDictionary = new RouteValueDictionary();
  NameValueCollection Qstr = null;
  if (filterContext.HttpContext.Request.RequestType == "GET")
  {
  Qstr = HttpUtility.ParseQueryString(filterContext.HttpContext.Request.Url.Query);
  foreach (string item in Qstr)
  {
  redirecttargetDictionary.Add(item, Qstr[item]);
  }
  if (Qstr["mid"] == null)
  {
  redirecttargetDictionary.Add("mid", mid);
  }
  if (Qstr["mod"] == null)
  {
  redirecttargetDictionary.Add("mod", mod);
  }
  filterContext.Result = new RedirectToRouteResult(redirecttargetDictionary);
  }
  }
  }
  </code></pre>
  
  <p>This code works fine.
  -check for quesrystring exsist if no
  -then take qstring value from 'Urlreferrer'
  -if request type is GET
  -then add two querystring with exsisting querystring</p>
  
  <p>But but I having problem if querystring in current request has <code>null</code> value url like <code>http://localhost:53372/question/index?type=&amp;stage</code>.if this ll b the current request url then code ll check for mid n mod qstring as its not exsist it will add both the qstring with exsisting type n stage but value ll b null then before hitting action again <code>OnActionExecuting()</code> get call this time first 'if' is not true and then <code>index</code> method get call but I m not getting type n stage querystring which suppose to null I found url in address bar is <code>http://localhost:53372/question/index?mid=1&amp;mod=5</code>.
  If I remove filter the I got URL <code>http://localhost:53372/question/index?type=&amp;stage=&amp;mid=1&amp;mod=5</code> here I m getting both stage n type querystring though its null.</p>
  
  <p><strong>Edited--</strong></p>
  
  <pre><code>[HttpGet]
          public ActionResult Index(ProjectType? projectType, int? projectStageID, int? page)
          {
              int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
              IPagedList&lt;ProjectModule&gt; moduleList = null;
              IDictionary&lt;string, string&gt; queryParam = new Dictionary&lt;string, string&gt;();
              queryParam["ProjectType"] = string.Empty;
              queryParam["ProjectStageID"] = string.Empty;
              ViewBag.ProjectType = null;
              ViewBag.ProjectStage = null;
              ViewBag.message = "";
              if ((projectType != null || projectType.HasValue) &amp;&amp; projectStageID.HasValue &amp;&amp; page.HasValue)
              {
  
                  queryParam["ProjectType"] = Request.QueryString["ProjectType"];
                  queryParam["ProjectStageID"] = Request.QueryString["ProjectStageID"];
                  //
                  //Set View Bag
                  //
                  ViewBag.ProjectType = Enum.Parse(typeof(ProjectType), Request.QueryString["ProjectType"]);
                  ViewBag.ProjectStage = Convert.ToInt32(Request.QueryString["ProjectStageID"]);
                  //
                  // Set Query String formcollection for Pagging purpose
                  //           
                  ViewBag.QueryParam = queryParam;
                  moduleList = new ProjectModuleService().GetProjectModulesByProjectStageID(Convert.ToInt32(Request.QueryString["ProjectStageID"])).ToPagedList(currentPageIndex, Utility.ConstantHelper.AdminDefaultPageSize); ;
                  if (moduleList.Count == 0)
                  {
                      ViewBag.message = "Record(s) not found.";
                  }
                  return View(moduleList);
  
              }
              else
              {
                  if (!string.IsNullOrEmpty(Request.QueryString["ProjectType"]) &amp;&amp; !string.IsNullOrEmpty(Request.QueryString["ProjectStageID"]) &amp;&amp; !string.Equals(Request.QueryString["ProjectStageID"], "0"))
                  {
                      if (!string.IsNullOrEmpty(Request.Params.Get("Index")))
                      {
                          queryParam["ProjectType"] = Request.QueryString["ProjectType"];
                          queryParam["ProjectStageID"] = Request.QueryString["ProjectStageID"];
                          //
                          //Set View Bag
                          //
                          ViewBag.ProjectType = Enum.Parse(typeof(ProjectType), Request.QueryString["ProjectType"]);
                          ViewBag.ProjectStage = Convert.ToInt32(Request.QueryString["ProjectStageID"]);
                          //
                          // Set Query String formcollection for Pagging purpose
                          //           
                          ViewBag.QueryParam = queryParam;
                          moduleList = new ProjectModuleService().GetProjectModulesByProjectStageID(Convert.ToInt32(Request.QueryString["ProjectStageID"])).ToPagedList(currentPageIndex, Utility.ConstantHelper.AdminDefaultPageSize); ;
                          if (moduleList.Count == 0)
                          {
                              ViewBag.message = "Record(s) not found.";
                          }
                          return View(moduleList);
                      }
  
                      else if (!string.IsNullOrEmpty(Request.Params.Get("Create")))
                      {
                          return RedirectToAction("Create", new { projectStageID = Convert.ToInt32(Request.QueryString["ProjectStageID"]) });
                          //return RedirectToAction("Create", new { projectStageID = Convert.ToInt32(Request.QueryString["ProjectStageID"]), projectType = Enum.Parse(typeof(ProjectType), Request.QueryString["ProjectType"]) });
                      }
  
                  }
                  if (Request.QueryString["ProjectType"] == "" || Request.QueryString["ProjectStageID"] == "" || string.Equals(Request.QueryString["ProjectStageID"], "0"))
                  {
                      ViewBag.message = "Please select all fields.";
                      return View();
                  }
                  return View();
              }
          }
  </code></pre>
  
  <p><strong>What I m doing wrong?</strong></p>