关闭保存对话框时出现问题jeasyui grid

时间:2016-11-22 08:58:56

标签: c# asp.net-mvc datagrid

我在做的时候遇到了问题 http://www.jeasyui.com/tutorial/app/crud/index.html

保存新项目后,我已成功更新数据库,但当javascript调用saveUser函数关闭对话框并刷新网格时,我总是遇到此错误:

Uncaught SyntaxError: Unexpected token )
at HTMLFormElement.success (http://localhost:58137/scripts/scripteasyui.js:22:44)
at HTMLIFrameElement.cb (http://www.jeasyui.com/easyui/jquery.easyui.min.js:7707:14)
at HTMLIFrameElement.handle (http://code.jquery.com/jquery-1.6.min.js:16:32793)
at HTMLIFrameElement.k (http://code.jquery.com/jquery-1.6.min.js:16:29553)

我正在使用MVC c#,这是我的代码:

对于视图html上的头部

 <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/color.css">
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/demo/demo.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
<script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<script src="~/scripts/scripteasyui.js"></script>

用于scripteasyui.js文件:

var url;
function newBrand() {
    $('#dlg').dialog('open').dialog('center').dialog('setTitle', 'New User');
    $('#fm').form('clear');
    url = 'SaveBrands';
}
function editBrand() {
    var row = $('#dg').datagrid('getSelected');
    if (row) {
        $('#dlg').dialog('open').dialog('center').dialog('setTitle', 'Edit User');
        $('#fm').form('load', row);
        url = 'update_user.php?id=' + row.id;
    }
}
function saveBrand() {
    $('#fm').form('submit', {
        url: url,
        onSubmit: function () {
            return $(this).form('validate');
        },
        success: function (result) {
            var result = eval('(' + result + ')');
            if (result.errorMsg) {
                $.messager.show({
                    title: 'Error',
                    msg: result.errorMsg
                });
            } else {
                $('#dlg').dialog('close');      // close the dialog
                $('#dg').datagrid('reload');    // reload the user data
            }
        }
    });
}
function destroyBrand() {
    var row = $('#dg').datagrid('getSelected');
    if (row) {
        $.messager.confirm('Confirm', 'Are you sure you want to destroy this user?', function (r) {
            if (r) {
                $.post('destroy_user.php', { id: row.id }, function (result) {
                    if (result.success) {
                        $('#dg').datagrid('reload');    // reload the user data
                    } else {
                        $.messager.show({   // show error message
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    }
                }, 'json');
            }
        });
    }
}

用于控制器上的save方法

public void SaveBrands()
    {
        string brandid = Request.Form["brandid"];
        string brandname = Request.Form["brandname"];
        using (ItemsEntities db = new ItemsEntities())
        {
            db.Brands.Add(new Brand { BrandID = brandid, BrandName = brandname });
            db.SaveChanges();
        }

    }

用于显示列表数据

  public JsonResult ShowBrands(string sidx, string sort, int page, int rows)
        {
            sort = (sort == null) ? "" : sort;
            int pageIndex = Convert.ToInt32(page) - 1;
            int pageSize = rows;

            using (ItemsEntities db = new ItemsEntities())
            {
                var brandqry = db.Brands.OrderBy(e => e.BrandID);
                int RecCount = brandqry.Count();
                var totalPages = (int)Math.Ceiling((float)RecCount / (float)rows);

                var jsonData = new
                {
                    total = totalPages,
                    page,
                    records = RecCount,
                    rows = brandqry.ToList(),
                };
                return Json(jsonData, JsonRequestBehavior.AllowGet);  

            }
        }

1 个答案:

答案 0 :(得分:0)

我找到了我需要将结果序列化为jason for javascript

的结果参数的答案
130417173