Reputation: 5
I want to take the integer value from the string address. for example
http://www.testtest.com/?page=12
here, i want to take "12" in this address.
How can i do this in asp.net mvc ?
Upvotes: 1
Views: 1167
Reputation: 18586
@Ardman is correct, MVC will translate the value in the query string and convert it to a variable in the ActionResult Function.
Be aware though, the example provided requires an int called page to be passed so you can do the following to overcome this.
public ActionResult Index(int? page)
{
if(page.HasValue())
{
// Do somthing with the var
}
// Do something
}
You can also use the old method,
public ActionResult Index()
{
var Page Request.QueryString["page"]; //return page query string param as a string
}
Hope that provides a little more info.
Upvotes: 3
Reputation: 48547
In your controller, create a method with int
as a parameter
public ActionResult Index(int page)
{
// Do something
}
Upvotes: 3