写了一个html表单来上传数据
<form action="/bookmarks/new" method="post" enctype="multipart/form-data">
<label>
Text file:
<input type="file" name="textFile"><br>
</label>
<label>
Image file:
<input type="file" name="imageFile" accept="image/jpeg"><br>
</label>
<label>
Bookmark path:
<input type="text" name="bookmarkPath">
</label><br>
<input type="submit" value="Загрузить"/>
</form>
和一个应该接受两个文件和一个字符串的控制器方法
[HttpPost("new")]
public async Task<IActionResult> InsertBookmark(IFormFile textFile, IFormFile imageFile, [FromBody]string bookmarkPath)
我不明白什么不起作用,它给出了一个错误415 Unsupported Media Type
如何重新制作它以便您可以发送两个文件和一行?
我将从评论中移出答案:
您需要
[FromForm]
改用[FromBody]
它,因为它是bookmarkPath
作为multipart/form-data
.