aspnet / AspNetWebStack

ASP.NET MVC 5.x, Web API 2.x, and Web Pages 3.x (not ASP.NET Core)
Other
858 stars 354 forks source link

Override ActionFilterAttribute.OnActionExecuting can't returning JsonResult? #175

Closed mrhuo closed 6 years ago

mrhuo commented 6 years ago

I override ActionFilterAttribute.OnActionExecuting method, and returning an JsonResult like this:

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    filterContext.Result = new JsonResult()
    {
        Data = new RestResult(false, "This is json result."),
        ContentEncoding = Encoding.UTF8,
        ContentType = "application/json",
        JsonRequestBehavior = JsonRequestBehavior.AllowGet
    };
}

BUT, I received {}, no content? why? And in other ActionFilterAttribute methods, same result.

dougbu commented 6 years ago

@mrhuo thank-you for filing this issue. In order for us to investigate this issue, could you please provide us with a minimal repro project that illustrates the problem, preferably hosted in a GitHub repo?

In particular, what is a RestResult? If it's not a POCO object, dictionary, or other relatively-simple class, it's likely incompatible with Json.NET.

mrhuo commented 6 years ago

@dougbu I tried a lot of ways to recreate the situation at that time, but never again. I'll close this Issues first. If I find the problem again, I'll mention Issues again. Thank you very much for your reply.