I have the following method:
[HttpPost]
[AjaxOnly]
public JsonResult ValidateInput(string text)
{
return new EmptyJsonResult();
}
/// <summary>
/// returns a JSON result that is marked as being empty.
/// </summary>
public sealed class EmptyJsonResult : JsonResult
{
public EmptyJsonResult()
{
Data = new JsonResultData
{
Empty = true
};
}
}
public class JsonResultData
{
public bool Empty { get; set; }
public string[] Errors { get; set; }
}
I expected this to return {"Empty":true}
to the browser, but it returns {"Empty":true,"Errors":null}
instead.
Is there any attribute or something I can set in order to avoid returning nulls on objects I didn't populate?