In this Asp .Net MVC tutorial we will learn how to call the action method which is present in the different Controller in ASP.NET MVC using Html.ActionLink
How we can use
Html.ActionLink
:
@Html.ActionLink("Text To Display","ActionName","ControllerName","OptionalRouteValues","Optional_HTML_Attributes")
Html.ActionLink Example 1
When we want to call Action Method where View and Action method are inside same Controller.
@Html.ActionLink("Contact Us", "EnquiryForm")
This will generates following output:
Contact Us
Html.ActionLink Example 2
When we want to call Action Method which is present in a different controller from the Controller which has created the View.
@Html.ActionLink("Contact Us", "NewActionName", "NewControllerName",new{UserId=1},null)
This will generates following output:
Contact Us