Support for Http GET, POST, PUT, DELETE constraints
Imported from the CodePlex archive for reference purposes. Support for MvcCodeRouting has ended.
Commented on
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
Example:
[HttpGet]
public ActionResult Detail(string recordId) { // return record here }
[HttpPut]
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
MvcCodeRouting.RouteFactory.CreateRouteSettings(IEnumerable1 actions) in d:\foss\MvcCodeRouting\src\MvcCodeRouting\RouteFactory.cs:317
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.