忽略具有特定参数的路由

时间:2011-01-07 09:51:14

标签: model-view-controller parameters null routes

我有一个@ url.Action,我将参数传递给动作。

当参数为null时,我想不做任何事情并保持在同一页面上。

我所做的是以下内容:

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

行动没有执行,但我的问题是我得到了这个:

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

我当然不希望看到。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

为什么不在视图中使用条件,如果为true,则不会将文本呈现为链接,因此用户将无法单击它。

或者,如果您绝对想要将其设为链接但希望用户保持在同一页面上,则使用锚标记创建一个旧方式的链接并将其指向“#”。这样,它将呈现为链接,但在用户单击时不会执行任何操作。

相关问题