I have a pretty standard route like this, {controller}/{action}/{id}, where id is optional.
Consider these three PUT actions:
public void DoSimpleStuff(int id) {/*DoingStuff*/ }
public void DoMoreStuff(StronglyTypedObject sto) {/*DoingStuff*/ }
public void DoExtraStuff(int id, StronglyTypedObject sto) {/*DoingExtraStuff*/ }
DoSimpleStuff works out of the box.
To make DoMoreStuff work I needed to disable the model binder. So I implemented a custom IRequestContentReadPolicy returning RequestContentReadKind.AsSingleObject.
However, that doesn’t fix DoExtraStuff.
So my question is, what can I do to fix DoExtraStuff? Shouldn’t the route understand that only the last parameter comes from the content, and hence pass that type to my serializer?
PS: I realize they’ll change how this work, but I need a solution for this now. Creative answers appreciated.
In asp.net mvc 4 beta this was hard to do. In fact I had to work around it as I didn’t find a way (if there was one) to achieve this.
However, in asp.net mvc 4 rc you simply apply the
[FromBody]and[FromUrl]attributes to your action parameters, and you’re good to go. Nice! 🙂