Search code examples
asp.netasp.net-mvc-2visual-web-developerhtml.actionlink

How to use ASP.Net -- Html.ActionLink()


Okay, I'm pretty new to ASP.Net / MVC 2. Can anyone explain how to use the Html.ActionLink thing? I understand that the first parameter is the displayed text, but for the second one, what is the action name??


Solution

  • User action in the asp.net MVC framework is based around Controllers and Actions that enable you to create pages (or links) to specific sections.

    For example you might want a page to edit a Product so you have a Product Controller with an Edit Action. You can then create a Html ActionLink that will direct the user to this page.

    In summary the 'action' will be the ActionResult method you want to direct your user to.

    <%: Html.ActionLink("Edit Product", "Edit", "Product") %>
    
    public class ProductController : Controller
    {
        public ActionResult Index() // Index is your action name
        {
        }
    
        public ActionResult Edit(int id) // Edit your product
        {
        }
    }