1

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?

1

1 Answer 1

1

Modify your Customer object properties?

public class Customer
{
  public string GenderOrEmptyString {get {return this._gender ?? ""; }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yea, it would work but it is going to be a lot of work to make the changesince I use auto property declarations almost exclusively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.