无法将 ModelBinderAttribute 和 FromBody 结合用于控制器操作方法

问题描述 投票:0回答:0

遵循 .Net Framework 到 .Net Core MVC 的迁移, [Modelbinder] 与控制器操作参数中的第二个复杂类型之间的组合似乎不再起作用。

例如我尝试调用的方法:

[HttpPost]
public ActionResult GetResult([ModelBinder(typeof(ComplexDynamicModelBinder))] dynamic dynamicFormModel, [FromBody] RandomComplexType complexType) { 
// Do Something 
}

例如来自 Js 的电话:

const fetchHeaders = new Headers([
   ['__RequestVerificationToken', 'myveriftoken').value],
   ['x-requested-with', 'XMLHttpRequest']
]);
fetch(urlToAction, {
   method: 'POST',
   body: JSON.stringify({
      dynamicFormModel: { someProperties: "values" },
      complexType: { someProperties: "values" }
   }),
   headers: fetchHeaders
})
.then(console.log);

我所有不同的尝试总是得到 415 ...

感谢您以后的帮助

c# asp.net-mvc asp.net-core model-binding
© www.soinside.com 2019 - 2024. All rights reserved.