开发者

ASP.NET MVC form GET passing array

开发者 https://www.devze.com 2023-01-02 21:36 出处:网络
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:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号