Asp.net Web API - return data from actionfilter

后端 未结 3 1154
猫巷女王i
猫巷女王i 2021-02-04 02:25

I want to return a json object from the wep api actionfilter. How can I achieve this?

I can return the object from action but I need to return some data from the actionf

3条回答
  •  梦如初夏
    2021-02-04 03:23

    you can use HttpResponseMessage to create the response like that

    var output =  new Result() { Status = Status.Error.ToString(), Data = null, Message = arr };
    actionContext.Response = new HttpResponseMessage {
                    Content = new StringContent(JsonConvert.SerializeObject(output), Encoding.UTF8, "application/json"),
                    StatusCode = HttpStatusCode.OK
                };
    

提交回复
热议问题