我创建了自定义ActionResult
(简化):
public class FastJSONResult : ActionResult
{
public string JsonData { get; private set; }
public FastJSONResult(object data)
{
JsonData = JSON.Instance.ToJSON(data);
}
public override void ExecuteResult(ControllerContext context)
{
HttpResponseBase response = context.HttpContext.Response;
response.ContentType = "application/json";
response.Output.Write(JsonData);
}
}
并从我的 WebApi 控制器中使用它:
public ActionResult GetReport()
{
var report = new Report();
return new FastJSONResult(report);
}
现在的问题是,尽管在FastJSONResult
构造函数中我的对象完美地序列化,但ExecuteResult
永远不会被调用,并且作为响应,我最终得到了像这样的对象
{"JsonData":"{my json object as a string value}"}
我究竟做错了什么?