easyui datagrid实现单行的上移下移,以及保存移动的结果

    开始接触easyui感觉他的封装真是极佳的,善假于物的思想使我们善于站在巨人的肩膀上,人家封装好这么好的插件直接让俺们使用,我们在需求不同可进行简单的调整。 

//调整展示次序加载图片
    function UpDownFormat(value, row, index) {
        //只有向下的按钮
        var data = $('#Convention').datagrid('getData');
        
        if (index == 0) {
            return ""
        } else if (index == data.total-1) {
            return ""
        } else {
            return "  "
        }
        
    }
 
 //点击进入界面时加载数据
$(document).ready(function () {

    var strConvention = "";
    //加载公约表格
    $('#Convention').datagrid({
        url: '/FreshConfiguration/QueryConvention?strConvention=' + strConvention,

        rownumbers: "true",
        title: "公约配置信息",
        loadMsg: '正在加载公约信息...',
        singleSelect: true,

        columns: [[
    { field: 'ck', checkbox: true, align: 'left', width: 60, align: "center" },

    {field: 'ConventionName', title: '公约名称', width: 385, align: "center", formatter: titleFormat},
    { field: 'isuse', title: '是否启用', width: 385, align: "center" },
    //{ field: 'ConventionContent', title: '公约内容', width: 290, align: "center" },
    { field: 'Adjust', title: '优先级次序', align: 'center', width: 383, formatter: UpDownFormat }//点击按钮进行上下行的数据交换
        ]],

        toolbar: [{
            id: 'btnAdd',
            text: '添加',
            iconCls: 'icon-add',
            handler: function () {
                window.location.href = "/FreshConfiguration/AddConventionConfigView"
                //showAddCon();
            }
        }, '-', {
            id: 'btnDelete',
            text: '删除',
            iconCls: 'icon-remove',
            handler: function () {
                doDelete();
            }

        }, '-', {
            id: 'btnUse',
            text: '启用',
            handler: function () {
                doUse();
            }
        }, {
            id: 'btnDelete',
            text: ' 不启用',
            handler: function () {
                doDisable();
            }

        }
        ],
        onHeaderContextMenu: function (e, field) {
        },
        onLoadSuccess: function (data) {
            $(".delUser").unbind("click");
            $(".delUser").bind("click", function () {
                alert($(this).attr("uid"));
                return false;
            });

            $(".editUser").unbind("click");
            $(".editUser").bind("click", function () {
                doEdit($(this).attr("uid"));
                return false;
            });
        }

    });
})

   以上是js的有关代码,前台界面的有关代码已经放到上面。


   存储到数据库需要调用controller的更新方法UpdateSortConvention,
#region 公约配置界面更新公约功能-赵尽朝-2016-8-24 16:37:32
        [ValidateInput(false)]
        [HttpPost]
        public void UpdateSortConvention(string ConventionContent, string ConventionName, string IsUse, string conventionSort, string ConventionID)
        {
            ConventionViewModel convention = new ConventionViewModel();
            convention.ConventionID = ConventionID;

            string str = "TimeSpan";

            if (conventionSort != null && conventionSort != "")
            {
                str += ",conventionSort";
                convention.conventionSort = int.Parse(conventionSort);
            }

            //内容
            if (ConventionContent != null && ConventionContent != "")
            {
                str += ",ConventionContent";
                convention.ConventionContent = ConventionContent;
            }
            //标题
            if (ConventionName != null && ConventionName != "")
            {
                str += ",ConventionName";
                convention.ConventionName = ConventionName;
            }

            //展示顺数
            if (IsUse != null && IsUse != "")
            {
                str += ",IsUse";
                convention.IsUse = int.Parse(IsUse);
            }

            //数组
            string[] strarray = str.Split(',');
            //调用后台方法
            conventionBll.UpdateSortConvention(convention, strarray);

        }
        #endregion

IBll层:
     bool UpdateSortConvention(ConventionViewModel StuConvention, string[] str);
Bll层:
#region 修改公约信息 UpdateSortConvention 赵尽朝2016-07-31
        public bool UpdateSortConvention(ConventionViewModel StuConvention, string[] str)
        {
            //实例化公约信息,并把viewmodel赋值给实体的属性
            freshconventionentity Conventioninfo = new freshconventionentity
            {  //更新整张表,给字段赋值 
                ConventionID = StuConvention.ConventionID, 
                ConventionName = StuConvention.ConventionName,
                ConventionContent = StuConvention.ConventionContent,
                IsUse = (StuConvention.isuse=="是")?1:0,
                conventionSort = StuConvention.conventionSort,
                ConventionTimestamp= DateTime.Now,
                isDelete = 0
            };
            this.ConventionCurrentDal.Update(Conventioninfo, q => q.ConventionID == StuConvention.ConventionID,str);
            //完成实务操作
            bool result = DbSession.SaveChanges() > 0;
            return result;
        }


   
遇到的错误:


一、检测到有潜在危险的 Request.Form 值

    这种问题是因为你提交的Form中有HTML字符串,例如你在TextBox中输入了html标签,或者在页面中使用了HtmlEditor组件等,解决办法是禁用validateRequest。

    如果你是.net 4.0或更高版本,一定要看方法3。此方法在asp.net webForm和MVC中均适用

方法1
在.aspx文件头中加入这句:<%@ Page validateRequest="false"  %>

方法2
修改web.config文件:

   
       
   



因为validateRequest默认值为true。只要设为false即可。

方法3:
web.config里面加上


   


    因为4.0的验证在HTTP的BeginRequest前启用,因此,请求的验证适用于所有ASP.NET资源,aspx页面,ashx页面,Web服务和一些HTTP处理程序等.


二、对一个或多个实体的验证失败。有关详细信息,请参见“EntityValidationErrors”属性        

   问题原因:(问题ef都是相同错误提示
       1. 非空列未插入值错误
       2. 多个表间外键列长度不一样
       3. ef上下文对象db为空 
       4. ef上下文设置属性为 db.Configuration.ValidateOnSaveEnabled = false;
       5. 内容长度超过列最大长度

你可能感兴趣的:(B/S)