4

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??

0

1 Answer 1

2

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
    {
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

and in this case you could have a view in Index() with this: <%: Html.ActionLink("Click me", "Edit"); %> in the asp:Content? What would then be an example of something you could have in the Edit action?
For a link to the edit page you would need <%: Html.ActionLink("click me", "Edit", "Product", new { id = 1 } %>. The Edit action in the product controller requires a value for 'id' so when you create your actionlink you need to specify the new {id = 1} (in this example).
So then how would I make this Edit action link to, let's say, HomeController (main page). And why would I need a variable declaration for it?
@DarkLightA you would of course want to edit a product. and the product must have a unique id. the extra variable is actually the id of product which you are going to edit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.