Mono bug using custom model binder (IModelBinder)

Gosh, this one required an hour or two.

I use a custom model binder to parse the http body for some json.

The error I got was smth like a BAD REQUEST http error, and in apache’s error_log an entry said mth like: Invalid URI in request { myjson } PUT /MyUrl HTTP/1.1.

In my controller the code looks like this:

public JsonResult Update([ModelBinder(typeof(GenericModelBinder))]Case casefile) { … }

I resolved the problem by adding a default value for casefile, i.e.:

public JsonResult Update([ModelBinder(typeof(GenericModelBinder))]Case casefile = null) { … }

It must have something to do with the order of the routing – it seems that in mono the custom ModelBinder is applied in some step after the routing itself, and my request does not map to any URL –> route pattern since the ModelBinder graps stuff from the HTTP Body, and not from the url itself.

Anyway, now it works 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s