toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.5k stars 259 forks source link

Unable to convert list property to Newtonsoft.Json.Linq.JArray #496

Closed GhayourAli closed 1 year ago

GhayourAli commented 1 year ago

Hi, I am trying to convert a list of objects to Newtonsoft.Json.Linq.JArray as follows

Newtonsoft.Json.Linq.JArray details = Model.Details != null ? (Newtonsoft.Json.Linq.JArray)Model.Details : null;`

But when I call engine.CompileRenderStringAsync, it gives the following error message Cannot convert type 'System.Collections.Generic.List' to 'Newtonsoft.Json.Linq.JArray'

I also tried iteration through the list rather than converting it to Newtonsoft JArray, but it also won't let me iterate over it.

Any help with this?

jzabroski commented 1 year ago

This looks like a beginning programming question. According to the JArray api https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Linq_JArray.htm , RazorLite.Detail needs to be a JToken. https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Linq_JToken.htm

Closing and locking. I'm not really here to answer beginning programming questions.