tags:

views:

89

answers:

3

I am using asp.net MVC.

I have edit page url like {controller}/Edit/2

so on the view page how can I get the ID from this URL?

I'm gonna put a link to redirect to some page with sending above ID.

EDIT Like

<%=Html.ActionLink("name", "Action", "Controller", new{ ID = ? } ) %>
A: 

I know of two ways: You can create your link and use the "ViewData" property to pass the link to your view or you can stronglyType the ViewPage.

Here is a link on strongly typing the view.

Chuck Conway
Not in the controller! but on view page!
Vikas
My bad, misread the question
Chuck Conway
+1  A: 

Put the ID in the ViewData in your action method, then your view can access the value from the ViewData.

Controller: ViewData["ID"] = id;

View: <%=Html.ActionLink("name", "Action", "Controller", new{ ID = (int)ViewData["ID"]} ) %>

Ben Robbins
+2  A: 

you can get it from the RouteData object

 <%=Html.ViewContext.RouteData.Values["id"].ToString() %>
Marwan Aouida