Reputation: 7097
I'm experencing some very strange behavior regarding the routing within an ASP.NET MVC 5 application.
I'm using RouteAttributes to describe the URIs in the following two actions:
[Route("status/{id:int}")]
public ActionResult ShipmentStatus(int id)
{ //do stuff & return partial view }
[HttpPut]
[Route("delivery/{id:int}")]
public ActionResult UpdateDelivery(int id, DeliveryModel model)
{
//do stuff with model to update db
return RedirectToAction("ShipmentStatus", new { id = model.ShipmentId });
}
Let's say that I submit a PUT request to the URI "/shipment/delivery/12345"
and the model contains ShipmentId = 54321
. When debugging I'm seeing that 54321 is within the RouteData and the redirect was to the URI "/shipment/status/54321"
, however inside the ShipmentStatus method the parameter injected into the method by ASP.NET id has the value, 12345, the id previously sent to the controller when the original put request was made instead of the value in the route object passed to the RedirectToAction method. The strange part is that the correct URI is generated during the redirect & the controller's RouteData object within the redirected method is correct. The injection of parameters is the only thing that appears wrong.
Here are some screen shots depicting the issue:
Generated URI passed from the redirect call:
RouteData object in controller along with the incorrect value being passed in debugging session:
I've tried to use a RouteValueDictionary as per this SO Q&A: https://stackoverflow.com/a/1300844/2359643, but it did not help resolve the issue. I have other actions (none of which use 'PUT', but are instead POSTs, GETs, and DELETEs) that return the exact same ActionResult
generated from the RedirectToAction()
call, and are functioning as intended. Has anyone else experienced this issue and if so how did you resolve it? Is there something that I'm doing incorrectly here that would cause this behavior?
Upvotes: 1
Views: 172
Reputation: 39
I'm not sure of this but you can try change the parameter name of ShipmentStatus from id to something else and make sure you debug till the point where UpdateDelivery is about to redirect so that you will be double sure about it
Upvotes: 1