views:

112

answers:

1

I'm attempting to process the body of an HTTP PUT request, but it seems that the MVC engine (or perhaps the ASP.NET stack underpinning it) isn't automatically parsing & populating the request's Form collection with the body data.

This does work as expected when doing a POST.

Note that the request's InputStream property does contain the expected data, and obviously I can build my own key/value collection using that, however I would have expected PUT to work the same way as a POST.

Am I missing something here?

Example action method:

[AcceptVerbs(HttpVerbs.Put)]
public ActionResult Purchase(int id, FormCollection data)
{
  // Do stuff with data, except the collection is empty (as is Request.Form)
}
A: 

Quote from the doc:

The Form collection retrieves the values of form elements posted to the HTTP request body, with a form using the POST method.

So instead of using Request.Form I would recommend you writing a custom model class that will hold the request data and pass it as action parameter. The default model binder will automatically populate the properties from the key/values passed in the request stream:

[AcceptVerbs(HttpVerbs.Put)]
public ActionResult Purchase(MyCustomModel model)
{
    // Do stuff with the model
}
Darin Dimitrov