How to pass parameter to controller using actionlink

19,948

The parameter you're passing is Id, but your parameter in your action is i.

Rename i to Id.

Html.ActionLink("Get Location", "Index", "Map", new { [email protected]},null)


public ActionResult Index(int id)
{
    var Id = from o in db.Objects where o.Id == id select o;
    return View(Id);
}
Share:
19,948
Thilina De Silva
Author by

Thilina De Silva

Updated on June 04, 2022

Comments

  • Thilina De Silva
    Thilina De Silva about 2 years

    I need to pass a view data(integer) to another controller.

    This is what i tried;

    @Html.ActionLink("Get Location", "Index", "Map", new { [email protected]},null)
    

    i need to pass this information to "Map" Controller's Index action method;

      public ActionResult Index(int? i)
        {
            var Id = from o in db.Objects where o.Id == i select o;
            return View(Id);
        }
    

    but the parameter doesn't get pass...is this the way to pass the parameter??When i put a break point i found that int? i is null..why is that??