views:

39

answers:

2

I have 2 views, one to return all the locations belonging to a project, the other returns a json file containing the locations that used to show them on a google map. Listing the locations works like this as the id is sent with the actionlink, but how do I send the project ID to the Map view?

public ActionResult GoogleMaps(int id)
  {
      return View(Project.Find(id).DeviceLocations);
  }


  //[AutoRefresh(DurationInSeconds = 30)]

  public ActionResult Map(int id)
  {
      var map = Project.Find(id).DeviceLocations;
      Locations l = new Locations();
      l.locations = map;
      return Json(l, JsonRequestBehavior.AllowGet);
  }
+1  A: 

Some people construct a model (class) specifically to handle all of the values being passed from the controller. So, your model would have a property called DeviceID, and would thus be strongly typed.

Alternately, you can use ViewData:

You can put this in your controller:

ViewData["DeviceID"] = id;

Then, in your view, you will need to cast it before you use it, like this:

(int)ViewData["DeviceID"]
RedFilter
but using ViewData is bad practice :)
Stefanvds
A: 

Include a get, set property "project ID" in your Locations class.

Kanishka