C# – ASP .NET Web API 2 FromForm model binder attribute

asp.net-web-apicmodel-bindingnet

Does ASP.NET Web API 2 (not core) contain also something like [FromForm] attribute for binding the action? Or can I add the dll from ASP.NET Core to a normal ASP.NET Web API 2? {

"Message": "The request entity's media type 'multipart/form-data' is not supported for this resource.",
"ExceptionMessage": "No MediaTypeFormatter is available to read an object of type 'FooBindModel' from content with media type

'multipart/form-data'.",
"ExceptionType": "System.Net.Http.UnsupportedMediaTypeException",
"StackTrace": " at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent
content, Type type, IEnumerable1 formatters, IFormatterLogger
formatterLogger, CancellationToken cancellationToken)\r\n at
System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage
request, Type type, IEnumerable
1 formatters, IFormatterLogger
formatterLogger, CancellationToken cancellationToken)" }

Best Answer

No, only FromUri and FromBody is available for ASP.NET Web API 2. You can look at the official documentation.

Also, why would you try to implement FromForm to ASP.NET Web API 2. You can simply configure your form action as GET and POST and pass the data to Web Api. In my opinion, it would be over engineering.

Related Topic