.net得到ajax传的值,汇总:ASP.NET Core中HttpContext获取传参数据,有哪些方式

一、原生方式:

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;

}

其它用法欢迎留言补充,谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值