Is it possible to avoid "NULL" bites on the client when binding JSON data to HTML UI?
I am using ASP.NET MVC + jQuery + jTemplates . The data comes from linq-to-sql classes, and these classes have quite a few null properties. When such properties become serialized and passed back to the client, I get this JSON:
[{"Id":1,"SuitId":1,"TypeId":null,"Type":null,"CourtId":null,"Court":null}]
Whey I bind this data to HTML. I have many "NULL" lines. I tried both manual binding mechanisms and JavaScript templates (jTemplate). The results are the same. I am currently dealing with this problem by βcombiningβ null values ββas follows:
$('#Elem').val(someVar||'');
But I do not want to do this manually.
I ask for advice if I:
- It can automatically convert properties with a null value to empty strings by setting up the serialization process or, possibly, selecting a third-party JSON serializer over the .NET JSON serializer.
- It can do something on the client side, for example, get around it using jQuery or templating mechanisms.
Thanks.
source
share