Hey I'm trying to receive data with Ajax in ASP.NET MVC, but this code doesn't seem to be working.
return this.Json(new
{
Result = (from obj in temp
select new
{
ObjektoAdresas = obj.ObjektoAdresas,
ĮrenginioNumeris = obj.ĮrenginioNumeris,
T1 = serializer.Serialize(obj.T1),
T2 = serializer.Serialize(obj.T2),
ŠiluminėEnergija = serializer.Serialize(obj.ŠiluminėEnergija),
ŠiluminėGalia = serializer.Serialize(obj.ŠiluminėGalia)
})
}, JsonRequestBehavior.AllowGet);
This throws a NotSupportedException with additional information: Only parameterless constructors and initializers are supported in LINQ to Entities.
As I understand I can't use serializer.Serialize(something) because it takes a parameter. Is that correct? And if so, how do I serialize this data to JSON before sending it?
EDIT: I changed the code after Will's response, but it still throws the same exception.
var temp = (from obj
in models
select obj).ToArray();
return this.Json(new
{
Result = (from obj in temp
select new
{
ObjektoAdresas = obj.ObjektoAdresas,
ĮrenginioNumeris = obj.ĮrenginioNumeris,
T1 = serializer.Serialize(obj.T1),
T2 = serializer.Serialize(obj.T2),
//Srautas = serializer.Serialize(obj.Srautas),
//VandensKiekis = serializer.Serialize(obj.VandensKiekis),
ŠiluminėEnergija = serializer.Serialize(obj.ŠiluminėEnergija),
ŠiluminėGalia = serializer.Serialize(obj.ŠiluminėGalia)
})
}, JsonRequestBehavior.AllowGet);