.net在Controller里的方法添加[HttpGet]和[HttpPost]

时间:2023-03-08 17:51:37

前端用post过来,Controller就要用[HttpPost],前端用get,Controller就要用[HttpGet],或者不管前端用什么,Controller都不加这些。

前端用post

$.ajax({
url: "/CommRecord/LockSendESMS",
type: "post",
data: {
id: data.ID,
isLock: isLock
},
success: function (data) {
}
});

Controller就要用[HttpPost]

[HttpPost]
public ActionResult LockSendESMS()
{
var sendSourceList = this.commRecordService.GetSendSource();

var list = (from n in sendSourceList
select new
{
DetailCode = n.ID,
DetailValue = n.DetailValue
}).ToList();

return Json(new { status = 1, data = list }, JsonRequestBehavior.AllowGet);
}

相关文章