I am trying to serialize an ICollection to JSON and pass it to my JS via hidden field on my HTML.
So far I have tried:
@Html.HiddenFor(model => JsonConvert.SerializeObject(model.Details), new { Id = "WorkOrderDetails" }) // also tried model.Details.ToArray(). model.Details.ToList()
var jsonSerialiser = new JavaScriptSerializer(); @Html.HiddenFor(model => jsonSerialiser.Serialize(model.Details), new { Id = "WorkOrderDetails" }) // also tried model.Details.ToArray(). model.Details.ToList()
It complains about an Incompatibility error: InvalidOparationException
I am thinking at this pace I will need to iterate my ICollection and pass every single detail individually.
Is there a better way to do it?