1 – 1 of 1
Blogger Yakko Warner said...

Note that I found an issue with parameterized routes. When posting JSON to a controller action where the route includes parameters, the model binder is called on each parameter, and this model binder attempts to bind the posted JSON to the parameters.

Example:
[HttpPost][Route("Customer/{customerId:int}/Vehicle/{vehicleId:int}/Policy/Create"]
public async Task Create(int customerId, int vehicleId, PolicyRequest policyRequest)

An error is thrown on the first (of three) calls to BindModel, as it tries to bind the JSON to customerId and throws the error "Error reading integer. Unexpected token: StartObject. Path '', line 1, position 1."

FromUri/FromBody attributes don't work here, probably because they're WebAPI attributes that MVC doesn't process. (Or maybe it does process them, but we end up in BindModel anyway -- either way, the problem remains.)

I've added some code to the top of BindModel that checks to see if the ValueProvider has assigned a value to the current ModelName (which it will when it resolves the route), and skips it instead of trying to deserialize the JSON.

27 August, 2014 11:22

Your civil comments are appreciated. Thanks!
You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.
Please prove you're not a robot