code_junkie

ASP.NET MVC passing an ID in an ActionLink to the controller

Nov 12th, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. <li>
  2. <%= Html.ActionLink("Modify Villa", "Modify", "Villa", new { @id = "1" })%></li>
  3.  
  4.  
  5. public ActionResult Modify(string ID)
  6. {
  7.  
  8. ViewData["Title"] =ID;
  9. return View();
  10. }
  11.  
  12. routes.MapRoute(
  13. "Default", // Route name
  14. "{controller}/{action}/{id}", // URL with parameters
  15. new { controller = "Home", action = "Index", id = "" } // Parameter defaults
  16. );
  17.  
  18. <%=Html.ActionLink("Modify Villa", "Modify", new {id = "1"})%>
  19.  
  20. <%=Html.ActionLink("Modify Villa", "Modify", "Villa", new {id = "1"}, null)%>
  21.  
  22. new { id = "1" }
Add Comment
Please, Sign In to add comment