Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm developing a web site in ASP.NET MVC 2. At some point, I get to a ActionResult in a controller and I obviously call method

return View();  

Is there any way, that I could pass QueryString into my view or attach parameters to the URL?

like image 542
dani Avatar asked Dec 03 '10 09:12

dani


1 Answers

A view is supposed to manipulate the model which is passed by the controller. The query string parameters are already present when the request was made to the corresponding action. So to pass a view model:

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

And now in your view you could use this model.

If on the other hand you don't want to return a view but redirect to some other controller action you could:

return RedirectToAction("SomeOtherActionName", new { ParamName = "ParamValue" });
like image 154
Darin Dimitrov Avatar answered Sep 21 '22 07:09

Darin Dimitrov