33

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Muhammad Adeel Zahid
  • 17,474
  • 14
  • 90
  • 155

1 Answers1

55

You can access route data using the ViewContext property:

<%= ViewContext.RouteData.Values["id"] %>
Community
  • 1
  • 1
Matthew Abbott
  • 60,571
  • 9
  • 104
  • 129