2011-01-07 62 views
0

我有一个@ 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 

对此我obvisouly不希望看到的。

感谢您的帮助。

回答

0

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

或者,如果你绝对想让它成为一个链接,但希望用户留在同一页面上,那么使用锚点标签并将其指向“#”,以旧式的方式创建链接。这样,它将被渲染为一个链接,但当用户点击它时什么也不做。