Pages

Tuesday 11 March 2014

Calling controller Action on ActionLink Click and passing arguments to controller MVC4 razor

Following code show how we can call controller action and pass the required data to the controller on click of Link/ActionLink. here name and order of parameter must be same in sending and receiving place.

/*Razor Code*/
@Html.ActionLink(item.PersonName, "GetInfo", new { Name = item.PersonName, age= item.PersonAge})
/*Controller Code*/
public ActionResult GetInfo(string Name, string age)
{
//then you can write your logic here
int age=convert.ToInt32(age);
return View();
}
/* Names and order of arguments passed in ActionLink and received in Controller action must be same*/

No comments:

Post a Comment