多种发布类型asp.net 5 MVC 6 API [英] Multiple Posted Types asp.net 5 MVC 6 API
问题描述
我可以将[FromBody]用于单个类型,但是有什么方法可以使用多个?
I can use [FromBody] for single type , but is there any way to use multiple?
从搜索和阅读中我无法找到一种方法,但是我不知道MVC 6中是否已添加一种方法.
From the searching and reading I've done there is not a way, but i don't know if a way has been added in MVC 6.
否则,最好从定制方式开始.
If not, where would be best to start with custom way.
在进行模型绑定之前,我应该研究什么并寻找最佳方法或放置位置,以便可以包括自己的方法?
What should i be researching and looking for best method or place to hook in just before model binding so i can include my own method?
推荐答案
最好的方法是创建一个复合包装:
The best way is to create a composite wrapper:
public class Wrapper
{
public ModelA A { get; set; }
public ModelB B { get; set; }
}
将包装器放在参数列表中,并将其标记为[FromBody]
.您不能多次使用该属性,因为假定正文的所有内容都与参数类型匹配.
Put Wrapper in the parameter list and mark that [FromBody]
. You can't use that attribute more than once because all of the contents of the body are assumed to match the parameter type.
这篇关于多种发布类型asp.net 5 MVC 6 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!