我正在IActionFilter中的响应对象中更改某些字段:
public async void OnActionExecuted(ActionExecutedContext context)
{
ObjectResult actionResult = (ObjectResult)context.Result;
IHavePrice havePrice = Cast<IHavePrice>(actionResult.Value);
var items = await _priceSetter.GetPrices<IHavePrice>(username, new List<IHavePrice>() { havePrice });
havePrice = items[0];
}
该代码有效:我可以看到context.Result.Value中的更改。但是在前端,我在响应对象中收到旧值。
您正在将items[0]
对象分配给本地havePrice
变量。
更改:
havePrice = items[0];
至:
actionResult.Value = items[0];