一、原生方式:
1.post(以ajax请求为案例,教大家用法)
$.ajax({
type: "post",
datatype: "json",
cache: false,
data: {
method: "add"
},
url: "../demo/post",
async: true,
success: function (data) {
if (data.isok) {
alert("成功");
}
else {
alert(“失败”);
}
}
});
iformcollection form = httpcontext.request.form;
string method = form["method"];
2.get(url传参为案例,教大家用法)
127.0.0.1/index/demo/get?num=1
iquerycollection queryparameters = httpcontext.request.query;
string num = queryparameters["num"];
二、以对象的形式接收参数(get/post通用):
public class pagemodel
{
public string titlename { get; set; }//筛选标题
public int currentpage { get; set; }//当前页
public int numcount { get; set; } //每页数量
public long id { get; set; } = 0;//默认id
public string token { get; set; } = "";//认证授权
}
public iactionresult userlist(pagemodel pagemodel)
{
return view(pagemodel);
}
三、路由实现传参(get/post通用):
127.0.0.1/index/menudelasync/1
public async task menudelasync(long id)
{
string jsonresult = "[]";
bool b = false;
b = await articleservice.delarticletypeasync(id);
if (b)
jsonresult = commonhelper.newgetjsonresult(1, "删除成功");
else
jsonresult = commonhelper.newgetjsonresult(-1, "删除失败");
return jsonresult;
}
其它用法欢迎留言补充,谢谢!