JS的json对象集的数据序列化和后台反序列化

JS代码

//保存按钮
        function customSave() {

            //验证数据对误
            var msg = '';
            var $trs = $('#datatable tr:gt(0)');
            var Arr = [];
            $trs.each(function (i) {
                $trs.eq(i).find('#GoodsQuestionTypeId').removeClass("wrongData");
                $trs.eq(i).find('input[name="QuestionQuantity"]').removeClass("wrongData");
                var obj = new Object();

                obj.IsDelete = 0;
                obj.GoodsQuestionManageId = $trs.eq(i).find('#GoodsQuestionManageId').val();
                obj.GoodsId = $trs.eq(i).find('#GoodsId').val();
                obj.Sku = $trs.eq(i).find('td[name="Sku"]').text();
                obj.OrderNumber = $trs.eq(i).find('td[name="OrderNumber"]').text();
                obj.GoodsName = $trs.eq(i).find('td[name="GoodsName"]').text();
                obj.GoodsQuantity = $trs.eq(i).find('td[name="GoodsQuantity"]').text();
                obj.QuestionQuantity = $trs.eq(i).find('input[name="QuestionQuantity"]').val();
                obj.GoodsQuestionTypeId = $trs.eq(i).find('#GoodsQuestionTypeId').val();//获取下拉框选中的值value
                obj.TypeName = $trs.eq(i).find('#GoodsQuestionTypeId').find("option:selected").text();//获取下拉框选中text
                obj.Remarks = $trs.eq(i).find('#Remarks').val();

                if (obj.QuestionQuantity == "") {
                    obj.QuestionQuantity = 0;
                }
                if (obj.QuestionQuantity > 0 && obj.GoodsQuestionTypeId == "0") {//未选择
                    msg += "第" + (i + 1) + "行未选择问题类型!<br>";
                    $trs.eq(i).find('#GoodsQuestionTypeId').addClass("wrongData");
                }
                if (obj.QuestionQuantity > 0 && obj.QuestionQuantity > obj.GoodsQuantity) {
                    msg += "第" + (i + 1) + "行问题数量不能大于商品数量!<br>";
                    $trs.eq(i).find('input[name="QuestionQuantity"]').addClass("wrongData");
                }
                if (obj.QuestionQuantity == 0 && obj.GoodsQuestionManageId!=0) {//删除此行
                    $('#delIds').val($('#delIds').val() + obj.GoodsQuestionManageId + ",");
                }
                //验证通过
                if (obj.QuestionQuantity > 0 && obj.GoodsQuestionTypeId != "0" && obj.QuestionQuantity <= obj.GoodsQuantity) {
                    Arr.push(obj);
                }
            });
            if (Arr.length==0&&msg=="") {
                msg = "请填写数据后再保存!";
            }
            if (msg == "") {//保存ajax
                $.ajax({
                    url: "/AfterSale/SaveGoodsQuestionManages",
                    data: { arrayList: JSON.stringify(Arr), delIds: $('#delIds').val() },
                    type: "POST",
                    dataType: "JSON",
                    success: function (result) {
                        // 登录超时及其他操作失败处理
                        if (!AjaxFaildOper(result)) { return false; }
                        if (result.Status) {
                            //提交成功
                            bootbox.alert({
                                title: "@LocalizationModel.Instance.Global_AlertTitle",
                                message: result.Msg,
                                callback: function () {
                                    location = location;//刷新
                                }
                            });
                        }
                        else {//显示错误
                            bootbox.alert({
                                title: "@LocalizationModel.Instance.Global_AlertTitle",
                                message: result.Msg
                            });
                            btnSave.attr("disabled", false);
                        }
                    }
                })
            }
        } 

Model实体类代码

    [Serializable]
    public class GoodsQuestionManageModel : BaseModel
    {
    }

Controller后台代码:

        public ActionResult GoodsQuestionManages(GoodsQuestionManageModel model)
        {
            // 商品问题管理信息
            Dictionary<string, dynamic> entities = goodsQuestionManageService.Get(model);
        }

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页