2

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

This is what i tried;

@Html.ActionLink("Get Location", "Index", "Map", new { Id=@item.Id},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??

Thilina De Silva
  • 391
  • 2
  • 13
  • 25

1 Answers1

7

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 { id=@item.Id},null)


public ActionResult Index(int id)
{
    var Id = from o in db.Objects where o.Id == id select o;
    return View(Id);
}
Antony Koch
  • 2,043
  • 1
  • 16
  • 23