开发者

Ignore route with a specific parameter

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

When the parameter is开发者_C百科 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.


Why don't you use a condition in your view that, if true, does not render the text as link so the user will not be able to click it.

Or, if you absolutely want to make it a link but want the user to stay on the same page then create a link the old fashioned way, using the anchor tag and point it "#". That way, it will be rendered as a link but will do nothing when the user clicks it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜