2011-01-07 64 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,則不會將文本呈現爲鏈接,因此用戶將無法點擊它。

或者,如果你絕對想讓它成爲一個鏈接,但希望用戶留在同一頁面上,那麼使用錨點標籤並將其指向「#」,以舊式的方式創建鏈接。這樣,它將被渲染爲一個鏈接,但當用戶點擊它時什麼也不做。