AvinashK
AvinashK

Reputation: 3423

Html.Actionlink Method in Razor

I have a table in my database which stores events. I am currently on my Homecontroller's index view page and I need to post a link to the edit method of my EventsController which takes in the ID of an event and edits it. Can I do this:-

@Html.ActionLink("Edit", "~/Controllers/EventsController.cs/Edit", new { id=item.ID })

or do I have to write something else to achieve my motive. Thanks.

Upvotes: 1

Views: 247

Answers (3)

Satpal
Satpal

Reputation: 133403

You can use

@Html.ActionLink("Edit", "Edit", "Events", new { id=item.ID }, null)

You can use overload, LinkExtensions.ActionLink Method (HtmlHelper, String, String, String, Object, Object)

For more info visit LinkExtensions.ActionLink

Upvotes: 4

Pushkar
Pushkar

Reputation: 112

You can use the code as

@Html.ActionLink("Edit", "EventsController", new { id=item.ID })

There are different overloads available for "ActionLink", check them out. eg.

http://microsoftmentalist.wordpress.com/2011/09/23/asp-net-mvc-17-html-actionlink-and-html-routelink-helper-methods/

In case you controller is placed in some different location (may be because of area ), you will have to specify it.

Upvotes: 2

Boris Parfenenkov
Boris Parfenenkov

Reputation: 3279

You can use following:

@Html.ActionLink("Link Text", "Edit", "Events", new { id=item.ID })

Upvotes: 1

Related Questions