I suggest you take a look at the limitations of the route. Creating a route restriction requires that the integer be passed as the parent element, and if it is not specified, the route will not match, and the default value is 404.
Here is an example:
routes.MapRoute( name: "MyController", url: "MyController/{parentid}", defaults: new { controller = "MyController", action = "Index" }, constraints: new { parentid = @"\d+" } );
For more information on route restrictions, see this article.
The only drawback of this approach is that the regular expression does not check if the input value is long or something big. However, if this is a concern, you can easily create a custom route restriction that will check if the input value can be parsed as long .
source share