Ignore route with a specific parameter

Posted by Vivien on Stack Overflow See other posts from Stack Overflow or by Vivien
Published on 2011-01-07T09:51:13Z Indexed on 2011/01/07 9:54 UTC
Read the original article Hit count: 242

Filed under:
|
|
|

Hello,

I have an @url.Action in which I pass a parameter to the action.

When the parameter is null, I would like to just do nothing and stay on the same page.

What I have done is the following:

routes.MapRoute(
           null,               
           "Test/View/{Id}",
           new { controller = "Test", action = "View" },
           new { Id = @"\d+" } //id must be numerical
           );
routes.IgnoreRoute("Test/View/{*pathInfo}");

The action is not executed but my problem is that I get this:

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Test/View

Which I obvisouly do not want to see.

Thanks for your help.

© Stack Overflow or respective owner

Related posts about mvc

Related posts about parameters