In this blog we will learn how to call the action method which resides in the different controllers in ASP.NET MVC, first, we need to pass the following parameters in ActionLink are as follows, The following code snippet can be written in view or partial view.
- @Html.ActionLink("Index", "ActionName", "ControllerName", null, new { id = "OT",style = "color: white" })
In the preceding code,
- The index is the ActionLink Name
- ActionName is the View name or ActionResult Name.
- ControllerName will be the name of our controller.
After implementing the code in parent view, the entire code will be look like as follows,
- @{
- ViewBag.Title = "Parentview";
- }
-
- <h2>Parentview</h2>
- @*To call same same controller view*@
- @Html.ActionLink("Index", "ActionName")
-
- @*To call another controller view*@
- @Html.ActionLink("Index", "ActionName", "ControllerName", null, new { id = "OT", style = "color: white" })
- Summary
I hope the preceding explanation will help you to learn how to call cross-controller action methods. If you have any suggestion then drop the comment in the comment box