Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to check a json property is empty or not in razor page

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 @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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading