编辑行始终在 Controller 中调用函数

Edit row always cal function in Controller

为什么在 jqGrid 中保存行总是调用 Controller 中的 1 个函数测试? 我使用 jqgrid 4.6.0

在 Controller 中,我创建了一个像这样的视图方法

public class TesMasterDataController : Controller
{
     public ActionResult test()
     {
       // debug here
       return View();
     }
 }

通过 JQgrid 为任何数据视图创建任何网格负载。

在 onCellSelect 上打开任意行进行编辑:

onCellSelect: function (rowid) {
              $("#" + gridId).jqGrid("editRow", rowid, false, "clientArray");
              setTimeout(jQuery("#" + gridId).saveRow(rowid, {
                 successfunc: function () {
                   return true;
                }
               }, "clientArray"), 300);
            }

Debug at controller 测试方法可以看到,函数saveRow总是调用它,虽然我已经设置了url null?

onCellSelect回调的代码很奇怪,因为有很多东西,但你的主要问题是saveRow的错误用法。目前您以下面的形式使用它

.saveRow(rowid, {
           successfunc: function () {
               return true;
           }
       }, "clientArray");

方法saveRow可用于以下形式之一:任一

.saveRow(rowid, {
           url: "clientArray",
           successfunc: function () {
               return true;
           }
       });

.saveRow(rowid,
         function () {
             return true;
         },
         "clientArray");

另外,建议不要使用retro version 4.6.0,它已经有3.5年了。 jqGrid 有两个主要分支:首先是 "free jqGrid", which I develop and which can be used for free under the same licenses like jqGrid 4.6, and commercial "Guriddo jqGrid JS", which develop Tony Tomov. I recommend you to choose one from the products and update jqGrid 4.6 to the latest version of the corresponding product. The current version of free jqGrid is 4.15.2. You can load it directly from CDN (see the wiki article). To test it you will need just change 3 lines of your code: the URLs from which you load jqGrid css/js files. Free jqGrid is compatible with jqGrid 4.6, but it supports a lot of new features. You can look at here