0

In my ASP.NET MVC application, I want to use this ASP.NET MVC Attribute Based Route Mapper, first announced here.

I am trying to do a RESTful API using this, and I don't understand how to differentiate from Get vs. post.

The GET is found, but when I try to POST, the route doesn't map, and I get a 404. Please advise.

See Code:

[HttpGet]
[Url("organizations/{organizationId?}/alerts/", Order = 1)]
public JsonResult List(Guid? organizationId) {
    ...
    return Json(data, JsonRequestBehavior.AllowGet);
}

[HttpPost]
[Url("organizations/{organizationId?}/alerts/", Order = 2)]
public JsonResult Send(Guid? organizationId, string message) {
    ...
    return Json(data, JsonRequestBehavior.AllowGet);
 }
Community
  • 1
  • 1
Chris Kooken
  • 32,730
  • 15
  • 85
  • 123

1 Answers1

1

Thanks to @Thechoyce for helping me. Simply renaming the send action to "List" fixed the problem. They need to both be the same to overload.

[HttpGet]
[Url("organizations/{organizationId?}/alerts/", Order = 1)]
public JsonResult List(Guid? organizationId) {
    ...
    return Json(data, JsonRequestBehavior.AllowGet);
}

[HttpPost]
[Url("organizations/{organizationId?}/alerts/", Order = 2)]
public JsonResult List(Guid? organizationId, string message) {
    ...
    return Json(data, JsonRequestBehavior.AllowGet);
 }
Chris Kooken
  • 32,730
  • 15
  • 85
  • 123