Here is what I have:
var listAddresses = GetAddresses().ToList();
return Json(new JsonResult { Data = new SelectList(listAddresses, "Name", "Id") }, JsonRequestBehavior.AllowGet);
But I get the error 'System.Dynamic.ExpandoObject' does not contain a property with the name 'Name'.
listAddresses is consisted of 10 items. When I debug, when I watch each one of them, I go to Dynamic View and there is Name and Id. How to recolve this?
var listAddresses = GetAddresses().ToList();
var data = new
{
Data = new SelectList(listAddresses, "Name", "Id")
};
return Json(data, JsonRequestBehavior.AllowGet);
Json(...)
is a JsonResult
, you don't need both.