GrantC
GrantC

Reputation: 81

MVC 4 Web API File POST Error

I am having some issues with the MVC 4 Web-API accepting images. 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

I am getting the error Cannot implicitly convert type 'System.Web.HttpRequestBase' to 'System.Net.Http.HttpRequestMessage' on the line: HttpRequestMessage request = this.Request;

Anyone have any idea what is wrong?

Upvotes: 0

Views: 1488

Answers (1)

syneptody
syneptody

Reputation: 1280

Is you controller deriving from System.Web.Mvc.Controller or System.Web.Http.ApiController? Without seeing your code it sounds like you are deriving from 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.

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.

Upvotes: 3

Related Questions