ASP.NET MVC Routing Via Method Attributes GET vs. POST
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);
}
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);
}
精彩评论