简体   繁体   English

MVC 4 Web API文件POST错误

[英]MVC 4 Web API File POST Error

I am having some issues with the MVC 4 Web-API accepting images. 我在MVC 4 Web-API接受图像时遇到一些问题。 I am following this https://stackoverflow.com/a/10327789/385595 and http://www.asp.net/web-api/overview/formats-and-model-binding/html-forms-and-multipart-mime#multipartmime 我正在关注这个https://stackoverflow.com/a/10327789/385595http://www.asp.net/web-api/overview/formats-and-model-binding/html-forms-and-multipart- mime#multipartmime

I am getting the error Cannot implicitly convert type 'System.Web.HttpRequestBase' to 'System.Net.Http.HttpRequestMessage' on the line: HttpRequestMessage request = this.Request; 我收到以下错误:无法在行上将类型'System.Web.HttpRequestBase'隐式转换为'System.Net.Http.HttpRequestMessage':HttpRequestMessage request = this.Request;

Anyone have any idea what is wrong? 任何人都知道哪里错了吗?

Is you controller deriving from System.Web.Mvc.Controller or System.Web.Http.ApiController? 您的控制器是从System.Web.Mvc.Controller还是System.Web.Http.ApiController派生的? Without seeing your code it sounds like you are deriving from MVC Controller. 没有看到您的代码,听起来好像您是从MVC Controller派生的。

Both base classes expose an Request property, however for MVC controllers the Request is of type System.Web.HttpRequestBase and for Api Controllers the Request is of type System.Net.Http.HttpRequestMessage. 这两个基类都公开了Request属性,但是对于MVC控制器,请求的类型为System.Web.HttpRequestBase,对于Api控制器,请求的类型为System.Net.Http.HttpRequestMessage。

The exception that you are describing suggests that you controller is deriving from System.Web.Mvc.Controller when it should be deriving from System.Web.Http.ApiController. 您所描述的异常表明,当控制器应从System.Web.Http.ApiController派生时,它是从System.Web.Mvc.Controller派生的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM