明天的明天 永远的永远 未知的一切 我与你一起承担 ??

是非成败转头空 青山依旧在 几度夕阳红 。。。
  博客园  :: 首页  :: 管理

HttpWebResponse Post 前端控件数据,后台如何接收?

Posted on 2018-08-06 08:42  且行且思  阅读(721)  评论(0编辑  收藏  举报

MVC视图页:

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>test</title>
     <script src="/Content/js/jquery-1.10.2.min.js?v=2018071901" type="text/javascript"></script>
</head>
<body>
<form id="frSubmitOrder" action="" method="post">
<input id="O_LeagueID" name="O_LeagueID" type="hidden" value="1111" />
        <input id="O_Product_ID" name="O_Product_ID" type="hidden" value="2222" />
        <input id="O_HotelID" name="O_HotelID" type="hidden" value="3333" />
        <input id="O_RoomTypeID" name="O_RoomTypeID" type="hidden" value="4444" />
        <input id="O_RoomID" name="O_RoomID" type="hidden" value="5555" />
        <input id="appid" name="appid" type="hidden" value="6666" />
        <input id="ctoken" name="ctoken" type="hidden" value="77777" />

   <div class="submit-order-btn clickable red-btn color3" data-name="预订-提交订单">
            提交订单
        </div>

 </form>
 <script type="text/javascript">
     $(function () {
         //搜索 点击搜索
         $(".submit-order-btn").click(function () {
             $('#frSubmitOrder').submit();
         });
     });
</script>
</body>
</html>

 

mvc控制器:

        [HttpPost]
        public ActionResult test(string id)
        {
            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add("action", "Add");
            //Response.Write("<li>" + Request.Params.Keys[i].ToString() + " = " + Request.Params[i].ToString());
            for (int i = 0; i < Request.Form.Count; i++)
            {
                dict.Add(Request.Form.Keys[i].ToString(), Request.Form[i].ToString());
            }
            return Json(Post("http://localhost:57239/Ajax/Order.ashx", dict), JsonRequestBehavior.AllowGet);
        }

 

Order.ashx 接收post 来的数据:
        string _action = context.Request["action"];
        string appid = context.Request["appid"];
       

        if (context.Request.RequestType == "POST")
        {
            //接收并读取POST过来的XML文件流
            StreamReader reader = new StreamReader(context.Request.InputStream);
            String xmlData = reader.ReadToEnd();
        }