【发布时间】:2013-02-24 20:48:30
【问题描述】:
我有一个返回 json 结果的操作,但有些属性为空,我想将它们转换为空字符串。我听说我可以使用DefaultValue(""),但它仍然返回null 而不是空字符串。
动作是:
[HttpGet]
public ActionResult GetResults(string date)
{
var data= GetData(); // returns List<Foo>
var json = Json(data, JsonRequestBehavior.AllowGet);
return json;
}
Foo 类是:
public class Foo
{
public string Bar1;
[DefaultValue("")]
public int? Bar2;
}
【问题讨论】:
标签: c# asp.net asp.net-mvc json asp.net-mvc-4