首页 > 代码库 > .net在Controller里的方法添加[HttpGet]和[HttpPost]

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

前端用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 = http://www.mamicode.com/n.DetailValue
}).ToList();

return Json(new { status = 1, data = http://www.mamicode.com/list }, JsonRequestBehavior.AllowGet);
}

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