How to return View with QueryString in ASP.NET MVC 2?

I am developing a website in ASP.NET MVC 2. At some point, I get an ActionResult in the controller, and I obviously call the method

return View();  

Is there a way so that I can pass a QueryString to my view or attach parameters to a URL?

+5
source share
3 answers

You can try

public ActionResult Index()
{
    RouteValueDictionary rvd = new RouteValueDictionary();
    rvd.Add("ParamID", "123");
    return RedirectToAction("Index", "ControllerName",rvd);
}

Remember to enable this

using System.Web.Routing;

or just you can try it

return RedirectToAction("Index?ParamID=1234");
+3
source

The view is supposed to control the model that is passed by the controller. Query string parameters are already present when the request was made for the corresponding action. So, to view the view model:

var model = new MyViewModel
{
    SomeParam = "Some value"
}
return View(model);

, , .

, , , , :

return RedirectToAction("SomeOtherActionName", new { ParamName = "ParamValue" });
+8

POST. Request.QueryString .

, , .

. :

Html.BeginForm querystring

, . , , - , .

0

All Articles