开发者

Ignore route with a specific parameter

开发者 https://www.devze.com 2023-02-02 19:13 出处:网络
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.

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

精彩评论

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