开发者

Accessing route values in view Mvc.net

开发者 https://www.devze.com 2023-01-05 21:04 出处:网络
I\'m using default route of mvc2 like {controller}/{action}/{id}. I want to access that id field in my view. How can I do that开发者_运维技巧 without using TempData and ViewData?

I'm using default route of mvc2 like {controller}/{action}/{id}. I want to access that id field in my view. How can I do that开发者_运维技巧 without using TempData and ViewData?

If I have a url like http://server-name/home/edit/14 I need the value "14" in the view.


You can access route data using the ViewContext property:

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

精彩评论

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