1、Action方法既没加HttpGet,又没加HttpPost
public ActionResult Edit(string code,string name)
{
//表示既接收get请求,也接收post请求
}
post请求action
var ss = { "code": "aa",“name”:"张三"};
$.ajax({
type: 'post', url: '/User/UserInfo/Edit', data: ss, success: function (d) {
{
if (d == "OK") {
//dosth
}
else {
//dosth
}
};
}
});
get请求action
var ss = { "code": "aa",“name”:"张三"};
$.ajax({
type: 'get', url: '/User/UserInfo/Edit', data: ss, success: function (d) {
{
if (d == "OK") {
//dosth
}
else {
//dosth
}
};
}
});
二、Action标记为HttpGet或HttpPost
此种情况客户端只能对应的请求方式进行请求,否则会报404错误
Failed to load resource: the server responded with a status of 404 (Not Found)
本文介绍ASP.NET MVC框架中如何处理GET和POST请求。详细解释了当Action方法未指定请求类型时,默认接收两种请求的方式,并展示了具体的C#代码及jQuery AJAX调用示例。同时,还说明了标记为特定请求类型时的行为变化。
1884

被折叠的 条评论
为什么被折叠?



