ASP.NET MVC passes the identifier in ActionLink to the controller

I do not see to get the identifier that I am sending in html.ActionLink in my controller, this is what I am trying to do

<li> <%= Html.ActionLink("Modify Villa", "Modify", "Villa", new { @id = "1" })%></li> public ActionResult Modify(string ID) { ViewData["Title"] =ID; return View(); } 

What recommended the textbook that I followed, but it does not work, does it also fit? Length = 5 at the end of the URL!

Thanks in advance!

edit: here is the route I use, by default

  routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); 

It seems that someone lowered the two sentences below, but did not post their solution!

+84
c # asp.net-mvc
Nov 25 '08 at 10:07
source share
5 answers

It doesn't look like you are using the correct ActionLink overload. Try the following: -

 <%=Html.ActionLink("Modify Villa", "Modify", new {id = "1"})%> 

It is assumed that your view is located in the / Views / Villa folder. If not, then I suspect you need: -

 <%=Html.ActionLink("Modify Villa", "Modify", "Villa", new {id = "1"}, null)%> 
+183
Nov 25 '08 at 11:01
source share

In MVC 4, you can associate one view with another controller by passing an Id or primary key through

 @Html.ActionLink("Select", "Create", "StudentApplication", new { id=item.PersonId }, null) 
+19
Dec 08 '12 at 18:37
source share

Do not put @ in front of id

 new { id = "1" } 

Does the frame "translate" it into? Length when there is a mismatch in the parameter / route

+10
Nov 25 '08 at 10:48
source share

MVC 5 is very similar

 @Html.ActionLink("LinkText", "ActionName", new { id = "id" }) 
+3
May 12, '16 at 13:22
source share

The identifier will work with the @ sign in front, but after that we need to add one parameter. i.e. null

look like this:

 @Html.ActionLink("Label Name", "Name_Of_Page_To_Redirect", "Controller", new {@id="Id_Value"}, null) 
+1
Apr 09 '16 at 8:23
source share



All Articles