ASP.NET MVC form GET passing array
I have a form with a collection of checkbox's for a refine search function on my website.
I am trying to pass an array in a form GET but the URL looks like:
/search?filter=foo&filter=bar&filter=green
Is there a better way to pass this in MVC? Possible like
/search?filter=foo,bar,green开发者_JAVA百科
Thanks in advance.
There is now way you can change this URL. It is built by the browser.
You could change the URL by javascript before sending the request but the better way is to use the post redirect get pattern (PRG).
You first post to the controller and redirect to the url that you build in the controller. That way you have full controll over the URL.
EDIT
this is a sample
public ActionResult FilterResult()
{
RouteValueDictionary searchRoute = ControllerContext.RouteData.Values;
if (searchRoute["Filter"]==null)
{
searchRoute.Add("Filter","");
}
searchRoute["Filter"] = "filter1,filter2,filter3";
return RedirectToAction("Search", searchRoute);
}
精彩评论