• Ajax序列化表单为Json字符串POST到后台


    $.fn.serializeObject = function () {
                    var o = {};
                    var a = this.serializeArray();
                    $.each(a, function () {
                        if (o[this.name] !== undefined) {
                            if (!o[this.name].push) {
                                o[this.name] = [o[this.name]];
                            }
                            o[this.name].push(this.value || '');
                        } else {
                            o[this.name] = this.value || '';
                        }
                    });
                    return o;
                };
    
    $('input.pass').mouseup(function () {
                    alert(JSON.stringify($(this).parent().parent().serializeObject()) + '
    ' + typeof (JSON.stringify($(this).parent().parent().serializeObject())));
    
                    $.post('@Url.Action("CheckPartial", "Agent")', JSON.stringify($(this).parent().parent().serializeObject()))
                        .done(function (data) {
                            $(this).parents('div.custom-card').load(data);
                        })
                });




    [HttpPost]
    public ActionResult CheckPartial()//直接加参数获取不到POST过来的数据
    {
    Session["Id"] = 1;
    var UserID = Convert.ToInt32(Session["Id"]);

    
    

    using (var streamReader = new StreamReader(Request.InputStream))
    {
    var checkObject = JsonConvert.DeserializeObject<CheckPartial>(streamReader.ReadToEnd());

    
    

    using (HoldenZhongbaoEntities _context = new HoldenZhongbaoEntities())
    {
    //var checkObject = JsonConvert.DeserializeObject(checkJson);
    var checkOrderID = checkObject.OrderID as string;

    
    

    var order = _context
    .Cashes
    .Where(u => u.OrderID == checkOrderID)
    .FirstOrDefault();

    
    

    order.IsAdminCheck = checkObject.IsAdminCheck;
    order.AdminCheckTime = DateTime.Now;
    order.Note = checkObject.Note as string;

    
    

    _context.SaveChanges();

    
    

    return PartialView("CheckPartial", order);
    }
    }
    }

     

    这里

    .done(function (data) {
                            $(this).parents('div.custom-card').load(data);
    用的不对,load的参数是要发送GET请求时顺带的,局部刷新看下一篇
  • 相关阅读:
    VS2010 正则批量替换头文件路径
    VC++ 内存泄露与检测的一种方法
    命令行编译C++程序
    Link1123:转换到COFF期间失败:文件无效或损坏
    C语言基础知识
    PCL深度图像(2)
    PCL关键点(1)
    PCL采样一致性算法
    PCL滤波介绍(3)
    PCL滤波介绍(2)
  • 原文地址:https://www.cnblogs.com/Jayesslee/p/9244755.html
Copyright © 2020-2023  润新知