Is there an equivalent way to bind querystring parameters in an MVC Controller to FromUri, which it seems is only used in MVC API?
I have 2 pages that can have from 0 to 7 querystring parameters, depending on filters that the user selects. I am trying to find a clean effective way to manage the querystring parameters from the controller without having a bunch of if statements. The parameters are basically the same for each page so creating a queryParameter class that both pages can access would be ideal.
It's really easy in an API controller and I would like to do something similar.
Any ideas would be appreciated.
Thanks,
Rhonda
Edit.
Say I have the following class:
public class QueryStringParams : IEnumerable
{
public string Page { get; set; }
public string Top { get; set; }
public string Color { get; set; }
public string Size { get; set; }
public string Width { get; set; }
public string Price { get; set; }
public IEnumerator GetEnumerator()
{
yield return this.Page;
yield return this.Top;
yield return this.Color;
yield return this.Size;
yield return this.Width;
yield return this.Price;
}
}
In In my controller(s) I would like to have something like this:
public async Task Index(string pathAlias, [Bind(Prefix = "QueryStringParams")]QueryStringParams queryParams)
Similar to being able to do this in an API method.
public async Task Get(string pathAlias, [FromUri]QueryStringParams queryParams)
Then reference the querystring parameters like: var pageNumber = queryParams.Page;
The querystring would look something like this:
http://localhost:12330/br/womens-dresses-shop?page=2&Top=10&color=red
It may or may not have all of the parameters set at any one time.
Is that more clear?