Search code examples
asp.net-mvcasp.net-mvc-3urlroutevalues

Add Value to RoutValues and keep Current Values in ASP.NET MVC 3


I have a view with two form one of them for declare rows per page. In post action I need my Url be the same and just add new parameter. at now I use like this:

[HttpPost]
public ActionResult Index(FormCollection collection) {

    //Calculate Row Count

    return RedirectToAction("Index", new { RC = RowCount });

   }

with this implementation my all parameters lost and just RC = rowcountnumber replaced. How can I keep parameters and just add new RC to it? what is fastest way to do it? is any performance issue here?


Solution

  • check this, I am not sure is fastest or about performance issue, but worked:

    RouteValueDictionary rt = new RouteValueDictionary();
        foreach(string item in Request.QueryString.AllKeys)
          rt.Add(item,    Request.QueryString.GetValues(item).FirstOrDefault());
    
      rt.Add("RC", RowCount);
        return RedirectToAction("Index", rt);