2010-07-01 59 views
30

我使用默認路由mvc2,如{controller}/{action}/{id}。我想在我看來訪問那個id字段。我怎麼能不用TempDataViewData在視圖中訪問路由值Mvc.net

如果我有一個url像 http://server-name/home/edit/14 我需要值"14"在視圖中。

回答

53

您可以訪問使用ViewContext屬性路線數據:

<%= ViewContext.RouteData.Values["id"] %>