未应用对IActionFilter中的响应对象所做的更改

问题描述 投票:2回答:1

我正在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中的更改。但是在前端,我在响应对象中收到旧值。

c# asp.net-core .net-core asp.net-core-2.2 action-filter
1个回答
0
投票

您正在将items[0]对象分配给本地havePrice变量。

更改:

havePrice = items[0];

至:

actionResult.Value = items[0];
© www.soinside.com 2019 - 2024. All rights reserved.