This project is read-only.

Support for Http GET, POST, PUT, DELETE constraints

Mar 4, 2015 at 4:11 PM
Hey Max,

I am having problems with controllers in a RESTful web API.

I have two action signatures in the controller both with the same name. One is intended to retrieve a record (Http Get) and the 2nd is intended to update that record (Http Put). (Sometimes I have need for an Http Delete and/or Post as well.). These actions are tagged with
the appropriate System.Web.Mvc.HttpxxxAttributes

public ActionResult Detail(string recordId) { // return record here }

public ActionResult Detail(Record updatedRecord) { // update record here}
I get an MvcCodeRouting runtime error with the above ('An item with the same key has already been added.'). Is MvcCodeRouting not able to differentiate the two routes above?

A couple relevant lines from the call stack....

System.Collections.Generic.Dictionary2.Add(TKey key, TValue value) +10
1 actions) in d:\foss\MvcCodeRouting\src\MvcCodeRouting\RouteFactory.cs:317

Mar 4, 2015 at 4:25 PM
Please disregard Max. After reviewing my controller again (I had many other actions on this controller) I found an action 'Copy' that had the same signature (Record copiedRecord) but which hadn't been tagged with a System.Web.Mvc.HttpPutAttribute. Once action was decorated, no more complaints.

I am good to go!
Mar 5, 2015 at 3:36 PM
Still, a proper error message would be more helpful. I'll look into it.