How can I fill array with model properties in controller action and pass to view?

  • Thread starter Thread starter Nazanin.Eb
  • Start date Start date
N

Nazanin.Eb

Guest
Hi. I have a model with a table namely Resource that consist of multiple properties. I want define an array and fill that with Id,Latitude and Longitude properties in action namely DistanceMCalculate() in controller and pass this array to javascript in view in my MVC project.

this is my model in edmx:


public partial class Resource
{
public int Id { get; set; }
public int Code { get; set; }
public string Name { get; set; }
public Nullable<System.DateTime> StartHour { get; set; }
public string Address { get; set; }
public Nullable<System.DateTime> Arrivetime { get; set; }
public Nullable<int> ArriveTimeDuration { get; set; }
public Nullable<int> ProgressPercent { get; set; }
public Nullable<int> ResourceTypeId { get; set; }
public Nullable<decimal> Latitude { get; set; }
public Nullable<decimal> Longitude { get; set; }

public virtual ResourceType ResourceType { get; set; }
}
}


this is my action and I want add Id,Latitude and Longitude properties of model to an arraylist and pass to view in javascript. I need just array in view.how can I do it?

public ActionResult DistanceMCalculate()
{
var model= db.Resource.Where(p => p.ResourceTypeId == 1 && p.Latitude != null).ToList();

return Json();
}


Thanks a lot

Continue reading...
 
Back
Top