Make WebAPI support everything MVC does minus views.
I think most people expectations would rightfully (IMHO) that WebAPI would support everything MVC does minus any view rendering or ActionResult overhead. When I search the web I see many comments relating to "I can do X in MVC but not in WebAPI". Example: Multipart/form-data or jsonp handling works in MVC out of the box.
1 comment
-
Thanks for this suggestion! Could you please provide links to the comments that you found on the web so that we can take a look at them?
We do support multipart/form-data in ASP.NET Web API. The support is somewhat different than the MVC support because ASP.NET Web API uses formatters to handle the request body instead of model binding. This means you get the form data as a single object instead of potentially multiple parameters. The benefit of this approach is that you get a convenient formatting abstraction for dealing with multiple formats (XML, JSON, OData, etc). The downside is that the programming model is not as nice for dealing with form data.
You can override how ASP.NET Web API does parameter binding to get the MVC behavior. Ex see http://blogs.msdn.com/b/jmstall/archive/2012/04/18/mvc-style-parameter-binding-for-webapi.aspx. The extension is already available in WebApiContrib. We are considering adding it to the core runtime. If this is what you want, then could you please add a specific suggestion for this feature so that it can be voted on?
As for JSONP, it's not supported by MVC today, although you can implement support for it. The same is true for ASP.NET Web API and there is a JSONP implementation available in WebApiContrib. we are definitely looking at adding cross domain support to ASP.NET Web API including JSONP and CORS. Vote for this UserVoice item if this is what you want: https://aspnet.uservoice.com/forums/147201-asp-net-web-api/suggestions/2632112-out-of-the-box-jsonp-formatter.