开发者

ASP.NET MVC Routing Via Method Attributes GET vs. POST

开发者 https://www.devze.com 2023-02-03 18:06 出处:网络
In my ASP.NET MVC application, I want to use this ASP.NET MVC Attribute Based Route Mapper, first announced here.

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);
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消