手动将请求数据绑定到模型,而不是在操作的参数列表中

Bind the request data to a model manually instead of it being in the action's parameters list

我有一个处理不同类型(但相似)请求的操作。所以我需要请求数据根据几个外部输入绑定到不同的模型。

有没有办法做到这一点(以便模型不在操作的参数列表中,而是手动绑定)?

实现自己的IActionModelConvention实现,可以更改参数绑定规则。

可能有帮助的文章:Customising model-binding conventions in ASP.NET Core

Here and here 是 MVC github 存储库中的示例。