0

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?

Community
  • 1
  • 1
GrantC
  • 81
  • 6

1 Answers1

3

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.

syneptody
  • 1,250
  • 1
  • 10
  • 27
  • Thanks heaps this was the reason. I had to change Controller to ApiController when specifying the class, I got Controller because when I created the class I used the EmptyController template. – GrantC May 03 '12 at 22:26