1

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 ?

2 Answers 2

3

In your controller, create a method with int as a parameter

public ActionResult Index(int page)
{
    // Do something
}
Sign up to request clarification or add additional context in comments.

Comments

3

@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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.