Reputation: 10116
I have an ASP.NET MVC application that returns a Customer object that is converted to JSON using the Json() method.
return Json(Repository.Customer.Get(id));
One of the properties of the Customer object is Customer.Gender. If the Gender property contains a Null value, the JSON object received on the client contains
Gender: "<null>"
Is there a way to have the properties with Null values contain empty strings in the JSON object rather than the "null" text?
Upvotes: 1
Views: 1280
Reputation: 6425
Modify your Customer object properties?
public class Customer
{
public string GenderOrEmptyString {get {return this._gender ?? ""; }
}
Upvotes: 1