I have an action that returns json result, but some of the attributes are null and I want to convert them to empty strings instead. I heard I can use DefaultValue(""), but it's still returning null instead of empty string.
The action is:
[HttpGet]
public ActionResult GetResults(string date)
{
var data= GetData(); // returns List<Foo>
var json = Json(data, JsonRequestBehavior.AllowGet);
return json;
}
The Foo class is:
public class Foo
{
public string Bar1;
[DefaultValue("")]
public int? Bar2;
}