I am trying to implement POST-Redirect-GET in MVC using multiple named parameters.
I can do this with one parameter:
return RedirectToAction("MyGetView", new { bookId = id });
I could hardcode multiple parameters:
return RedirectToAction("MyGetView, new {bookId = id1, bookId=id2});
But how do I get from an IEnumerable< int> of Ids, which is of variable length, to a correct query string without constructing it by hand?
My current code looks like this:
var querystring= string.Join("", BookIds.Select(x => string.Format("bookId={0}&", x)));
querystring= querystring.Trim('&');
return Redirect("MyGetView?" + querystring);
It works fine, but it seems like there should be a better way.
(I want the parameters to be visible in the URL, so that users can bookmark the page. I believe this means I cannot use TempData.)