У меня есть контроллер, который возвращает список objects
в TempData
public ActionResult timelineIndex()
{
var jsondata = new
{
data = (
from t in ptr.GetAll()
select (new
{
id = t.pptid,
Owner = t.Owner,
Duration = t.totaldays,
Comp = t.Status,
StartDate = t.StartDate,
EndDate = t.EndDate
}).ToString())
};
TempData["id"] = jsondata.data.ToList();
return View();
}
Теперь, с моей точки зрения, я закодировал, используя @html.Raw(json.Encode)
var modeldata = @Html.Raw(Json.Encode(@TempData["id"])) ;
Я хочуцикл по всем объектам для этого я попробовал, но он показывает Undefined.
console.log(modeldata);
var array = [];
array = modeldata;
for (var i = 0 ; i<11 ; i++) {
var obj = modeldata[i];
alert(obj.id);
alert(obj.Startdate)
}
в массиве modeldata объекта идет.
(11) ["{ id = 1, Owner = erewrwer, Duration = 7, Comp = e…w, StartDate = 2018-09-19, EndDate = 2018-09-26 }", "{ id = 2, Owner = erewrwer, Duration = 7, Comp = , StartDate = 2018-09-19, EndDate = 2018-09-26 }", "{ id = 3, Owner = erewrwer, Duration = 11, Comp = , StartDate = 2018-09-19, EndDate = 2018-09-30 }", "{ id = 4, Owner = erewrwer, Duration = 11, Comp = …z, StartDate = 2018-09-19, EndDate = 2018-09-30 }", "{ id = 5, Owner = erewrwer, Duration = 11, Comp = …z, StartDate = 2018-09-19, EndDate = 2018-09-30 }", "{ id = 6, Owner = erewrwer, Duration = 11, Comp = …z, StartDate = 2018-09-19, EndDate = 2018-09-30 }", "{ id = 7, Owner = erewrwer, Duration = 11, Comp = …S, StartDate = 2018-09-19, EndDate = 2018-09-30 }", "{ id = 8, Owner = erewrwer, Duration = 11, Comp = …S, StartDate = 2018-09-19, EndDate = 2018-09-30 }", "{ id = 9, Owner = erewrwer, Duration = 11, Comp = …E, StartDate = 2018-09-19, EndDate = 2018-09-30 }", "{ id = 10, Owner = erewrwer, Duration = -204, Comp…D, StartDate = 2018-11-30, EndDate = 2018-05-10 }", "{ id = 11, Owner = erewrwer, Duration = 6, Comp = …S, StartDate = 2018-09-24, EndDate = 2018-09-30 }"]