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

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

回答1

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" });

回答2

You can try

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

Don't forget to include this

using System.Web.Routing;

or simply you can try this

return RedirectToAction("Index?ParamID=1234");
原文地址:https://www.cnblogs.com/chucklu/p/15509615.html