【问题标题】:Delete, No url is set in jqgrid删除,jqgrid中没有设置url
【发布时间】:2014-11-21 10:59:59
【问题描述】:

我正在使用jqgrid,当删除网格中的一行时,我收到警报“Delete selected record?”,当我点击确定时,我在onClickSubmit 中编写了一个代码来调用ajax控制器接受一些参数并删除记录。该功能运行良好。

但是当我单击警报中的“Delete”按钮时,我收到错误“No url is set”。现在,我的ajax 调用中有一个url,它执行该功能。为什么会抛出错误?

jqGrid:

var selectedRowId = "125";

     $("#AttachmentsGrid").jqGrid({

         url: '@Url.Action("LoadTransactionAttachments", "Home")',
         postData: { 'transactionId': selectedRowId },
         mtype: 'GET',
         datatype: 'json',
         jsonReader: {
             id: 'AttachmentId',
             repeatitems: false
         },
         height: 'auto',
         hidegrid: false,
         rownumbers: true,
         autowidth: true,
         shrinkToFit: false,
         rowNum: 10,
         pager: '#AttachmentsPager',
         caption: "Attachments",
         colNames: ['AttachmentName'],
         colModel: [{ name: 'AttachmentName', index: 'AttachmentName', formatter: imageFormatter, unformat: imageUnFormatter }],
         beforeRequest: function () {
             responsive_jqgrid($(".jqGrid"));
         },
         onSelectRow: function (id) {

             var statusId;
             attachmentId = id;
             var selectValues = jQuery('#AttachmentsGrid').jqGrid('getRowData', id);

             attachmentName = selectValues.AttachmentName;

             if (accessLevel.HasDeleteAttachmentAccess == true)
                 $("#del_AttachmentsGrid").show();
             else
                 $("#del_AttachmentsGrid").hide();

         },
         loadComplete: function () {
             UnBlockUI();
         }
     });

     jQuery("#AttachmentsGrid").jqGrid('navGrid', '#AttachmentsPager', {
         edit: false, add: false, del: true, search: false, refresh: true, refreshtext: ""
     }, {}, {}, {

        // url: '@Url.Action("UpdateDummyData", "Home")',

         // Delete attachment event.
         onclickSubmit: function (response, postData) {

             $.ajax({
                 url: '@Url.Action("DeleteSelectedTransactionAttachment", "Home")',
      datatype: 'json',
      data: { 'attachmentId': JSON.stringify(postData), 'attachmentName': attachmentName, 'transactionId': selectedRowId },
      type: 'POST',
      success: OnCompleteDeleteAttachments,
      error: function (xhr, status, error) {
          if (xhr.statusText == "Session TimeOut/UnAuthorized") {
              alert(xhr.statusText);
              window.location.href = '@Url.Action("LogOut", "Account")';
          }
          else
              alert(xhr.responseText);
      }
  });

当我在删除方法中提供一些我不需要的虚拟 url 时,它可以工作。我需要另一种方法来解决这个问题。?

仅供参考,这也发生在我使用form editing 编辑行期间。

【问题讨论】:

    标签: asp.net-mvc jqgrid


    【解决方案1】:

    在我看来,您尝试以错误的方式使用 Delete。您所做的是使用一些附加数据向'@Url.Action("DeleteSelectedTransactionAttachment", "Home")' 发出Ajax 请求,在成功删除的情况下在OnCompleteDeleteAttachments 内部执行一些未知的附加操作,并在statusText 中出现"Session TimeOut/UnAuthorized" 错误时执行附加错误处理。

    我认为正确的实现应该如下所示

    jQuery("#AttachmentsGrid").jqGrid('navGrid', '#AttachmentsPager', {
             edit: false, add: false, search: false, refreshtext: ""
        }, {}, {}, {
        url: '@Url.Action("DeleteSelectedTransactionAttachment", "Home")',
        serializeDelData: function (postData) {
            return {
                attachmentId: JSON.stringify(postData),
                attachmentName: attachmentName,
                transactionId: selectedRowId
            }
        },
        errorTextFormat: function (xhr) {
            if (xhr.statusText == "Session TimeOut/UnAuthorized") {
                window.location.href = '@Url.Action("LogOut", "Account")';
            } else {
                return xhr.responseText;
            }
        },
        afterSubmit: OnCompleteDeleteAttachments
    });
    

    【讨论】:

      猜你喜欢
      • 2012-07-29
      • 1970-01-01
      • 1970-01-01
      • 2012-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多