WebForm 和 mvc 获取get 和 post的方式

WebForm:(假如请求这个页面有get和post两种情况)

Request.ServerVariables("Request_Method")="POST"

Request.ServerVariables("Request_Method")="GET"

Request.RequestType=="POST"

Request.RequestType=="GET"

protected void Page_Load(object sender, EventArgs e)
{
        if (Request.RequestType == "POST")//表示请求过来的是Post请求
        {

                //获取参数值的方法

                string userName = Request.Form["UserName"];

                Response.Write(userName);
                Response.End();

        }else if(Request.RequestType == "GET")//表示请求过来的是Get请求

        {

                //获取参数值的方法

                string userName = Request.QueryString["UserName"];

                Response.Write(userName);
                Response.End();

        }

}

mvc的控制器中

[HttpPost]//表示请求过来的是Post请求
[ActionName("Index")]//当前action的名字为Index
public ActionResult Post(string UserName){

 

  return null;

}

 

[HttpGet]//表示请求过来的是get请求
[ActionName("Index")]//当前action的名字为Index
public ActionResult Get(string UserName){

 return null;

}

 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

浅谈,如果代码有问题,欢迎指出。

转载于:https://www.cnblogs.com/lswbk/p/4949500.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值