How To Call Action Method Using ActionLink in ASP.NET MVC

In this article we will learn how to call action method which resides in different controller 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 above code
  •     Index is the ActionLink Name
  •     ActionName is the View name or ActionResult Name.
  •     ControllerName will be name of our controller .
After implementing the code in parent view, the entire code will be look like as follows

Parentview.Cshtml

@{
    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

Post a Comment

www.CodeNirvana.in

Protected by Copyscape Online Copyright Protection
Copyright © Compilemode