如何在mvc中保存jquery jtable中关闭添加新记录弹出窗口?

时间:2014-03-15 08:35:50

标签: jquery asp.net-mvc jtable

我在我的CRUD应用程序中使用了jQuery的jTable插件。我的问题是,当我点击添加新记录时,会出现一个确认对话框,但在填写详细信息并单击保存按钮后,对话框不会消失,但是在刷新Jtable..how时添加了数据我可以关闭弹出窗口吗?

我的视图包含

$(document).ready(function () {

    $('#StudentTableContainer').jtable({
        title: 'Employee List',
        paging: true, //Enable paging
        sorting: true, //Enable sorting
        defaultSorting: 'Name ASC',
        //openChildAsAccordion: true, //Enable this line to show child tabes as accordion style
        actions: {
            listAction: '@Url.Action("Details")',
            deleteAction: '@Url.Action("Delete")',
            updateAction: '@Url.Action("Update")',
            createAction: '@Url.Action("Create")'


        },
        recordAdded: function (event, data) {
            $('#StudentTableContainer').jtable('reload');
        },
        fields: {
          UserId: {
                key: true,
                create: false,
                edit: false,
                list: false
            },
            FirstName: {
                title: 'FirstName',
                width: '10%'
            },
          LastName: {
               title: 'LastName',
                width: '10%'
          },
          EMail: {
              title:'EMail',
                width: '10%'
          },
          Address: {
              title: 'Address',
                width: '10%'
          },
          PhoneNo: {
              title:'PhoneNo',
                width: '10%'
          },
          Company: {
              title:'Company',
              width:'10%'
          },
          Designation: {
              title:'Designation',
              width:'10%'
          }
      }
  });

  //Load person list from server
  $('#StudentTableContainer').jtable('load');

我的控制器有Create方法包含

[HttpPost]    public JsonResult Create(UserList userList)         {

        try
        {
            userRepository.InsertUser(userList);
            return Json(new { Result = "OK" });

        }



        catch (Exception exception)
        {
            return Json(new { Result = "ERROR", Message = exception.Message });
        }
    }

4 个答案:

答案 0 :(得分:0)

jtable期望在返回的json中插入数据。

类似

{ “结果”: “OK”, “记录”:[{ “用户ID”: “169”, “姓”: “阁楼”, “名字”: “服务器”, “电子邮件”:“A @甲.COM”, “地址”: “根”, “PHONENO”: “12121212”, “公司”: “通”, “指定”: “经理”}]}

您可以安装Firebug

并检查是否收到此错误 jTable错误:服务器必须返回创建的Record对象。

答案 1 :(得分:0)

我想我和你有同样的问题。当试图添加新记录“加载数据”.gif即使收到Json消息也永远不会消失。两种可行的解决方案对我有用:

(坏的)在jtable.js =>搜索_reloadTable函数和注释行self._showBusy(self.options.messages.loadingMessage,self.options.loadingAnimationDelay);

(好的)尝试使用最新版本的JTable。我现在正在测试它,并且gif永远不会出现,一切都很完美

答案 2 :(得分:0)

您必须将添加的记录返回给json响应。

我不知道其他语言,但对于PHP,它看起来像:

$json['Result'] = "OK";
$json['Record'] = $lastInsertedRecord; // query the last insert id from db
print json_encode($json);

答案 3 :(得分:0)

记录必须是对象,而不是对象数组。你必须从浏览器检查json响应。

{"结果":" OK""记录":[{" ID":" 2" " ITEM_ID":" 6"" marked_number":" MN567"" p_model":" MDL"" p_number":" PNUM"" claimed_defects":" CLDEF"}]}

一定是这样的:

{"结果":" OK""记录" {" ID":" 2&#34 ;, " ITEM_ID":" 6"" marked_number":" MN567"" p_model":" MDL& #34;" p_number":" PNUM"" claimed_defects":" CLDEF"}}

另外一个问题,我在几天内处理这个问题,在这里用一个字母解决(记录与记录)