Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net adding parameter to url string

I'm displaying a list of filtered items in a page, and now I have to limit the displaying by paginating the results.

So if I have url parameters like these:

example.com/?category=pizza&period=today

where both category and period can also not being showed:

example.com/?period=today

example.com/

how can I add a "Next page" in the end that keeps any previous parameter and adds

&pagenum=5 

or if there are no parameters:

?pagenum=5

Tnx in advance!

like image 869
Attila Avatar asked Sep 16 '11 13:09

Attila


People also ask

How do I add a parameter to a query string?

Add a WHERE clause that contains the fields you want to add parameters to. If a WHERE clause already exists, check to see whether the fields you want to add parameters to are already in the clause. If they aren't, add them. Note that you need to add the same filter to each section of the query.

What is parameter string in URL?

URL parameters (also known as “query strings”) are a way to structure additional information for a given URL. Parameters are added to the end of a URL after a '? ' symbol, and multiple parameters can be included when separated by the '&' symbol.

How do I use FromUri in Web API?

Using [FromUri] To force Web API to read a complex type from the URI, add the [FromUri] attribute to the parameter. The following example defines a GeoPoint type, along with a controller method that gets the GeoPoint from the URI.


1 Answers

For serverside

string url = Request.Url.GetLeftPart(UriPartial.Path);
url += (Request.QueryString.ToString() == "" ) ? "?pagenum=1" : "?" + Request.QueryString.ToString() + "&pagenum=1";

You can pass in the page number depending on how you are handling this.

like image 117
Tim B James Avatar answered Oct 11 '22 22:10

Tim B James