How to avoid nullable action parameters (and if statements)
As you've seen by @Muhammad's answer (which is BTW the one to be accepted as the correct answer) it's easy to get optional parameters (any route parameters actually) into controller actions. All you you have to make sure is that they're nullable (because they're optional).
But since they're optional you end up with branched code which is harder to unit test an maintain. Hence by using a simple action method selector it's possible to write something similar to this:
public ActionResult Index()
{
// do something when there's not ID
}
[RequiresRouteValues("id")]
public ActionResult Index(int id) // mind the NON-nullable parameter
{
// do something that needs ID
}
A custom action method selector has been used in this case and you can find its code and detailed explanation in my blog post. These kind of actions are easy to grasp/understand, unit test (no unnecessary branches) and maintain.