C# 即使表单的enctype=";“多部分/表单数据”;标签
有谁能告诉我,当我们在方法中指定[FromBody]标记时,asp.net coreC# 即使表单的enctype=";“多部分/表单数据”;标签,c#,asp.net-core,asp.net-core-mvc,C#,Asp.net Core,Asp.net Core Mvc,有谁能告诉我,当我们在方法中指定[FromBody]标记时,asp.net coremvc framework做了什么 // POST api/values [HttpPost] public IActionResult register ([FromBody]CustomerViewModel custView) { if (ModelState.IsValid) { repo.create_customer(custView); return Ok(cus
mvc framework
做了什么
// POST api/values
[HttpPost]
public IActionResult register ([FromBody]CustomerViewModel custView)
{
if (ModelState.IsValid)
{
repo.create_customer(custView);
return Ok(custView);
}
return Redirect("/");
}
这是我们想要接收的视图模型public class CustomerViewModel
{
[Required(ErrorMessage = "Please enter your name!")]
public string name { get; set; }
//[Required(ErrorMessage = "Please upload your resume!")]
//public IFormFile cv { get; set; }
}
我注意到,当我没有使用[FromBody]标记时,我仍然可以正确地接收对象(将文件作为属性),当我添加[FromBody]时,它无法通过http接收文件流,为什么我们甚至想使用[FromBody]标记来接收http post
忘了提一下,它甚至与multipart标记都不起作用尝试将表单上的内容类型设置为“multipart/form data”。这是我们上传文件时应该使用的。规范是。您好,谢谢您的回复,我是通过遵循文档来完成的,因此我有了带有html的多部分标记,但它仍然不起作用。