1

Is there a way to set a default value on a parameter that was not passed, for eg:

    public ActionResult Index(int? page)
    {}

I'd like to have page=0 if no page was passed, so I can remove the nullable symbol. I do not want to do this in routing, just on the action itself.

2 Answers 2

4

Have you tried:

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

Comments

1

New in C# 2010 is the ability for optional parameters:

public ActionResult Index(int page = 0)     
{

} 

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.