I’ve a sample response value like this
{{
"transaction_order_line_items": [],
"payments": [],
}}
In .Net core Razor page how to check the "payments" is empty or not
I tried this following way but it’s not worked
@if(@transaction.payments!=null)
{
}
As well tried
@if(@transaction.payments.Length==0)
it says RuntimeBinderException: ‘Newtonsoft.Json.Linq.JArray’ does not contain a definition for ‘Length’
Please let me know how to check the value is empty or not
>Solution :
JArray does not expose a Length property, but it does expose both HasValues and Count properties that reveal whether or not the JArray contains child tokens.
You can change your check to the following:
@if (@transaction.payments.HasValues)