0

我需要调用以下 JsonResult 方法:

JsonResult Delete(int pubId)
{
    try
    {
        using (var ctx = new LibsysLiteContext())
        {
            var p = ctx.Publishers.Find(pubId);
            var allPublisher = ctx.Publishers.ToList();
            ctx.Publishers.Remove(p);
            var total = allPublisher.Count();
            return Json(new { success = true, data = allPublisher, total = total }, JsonRequestBehavior.AllowGet);
        }
        return Json(new RestResult { Success = true, Data = entity, Message = "Country  has been deleted" }, JsonRequestBehavior.DenyGet);
        return null;
    }
    catch (Exception e)
    {
        return Json(new RestResult { Success = true, Message = e.Message }, JsonRequestBehavior.DenyGet);
    }
}

来自 js 函数(deleteRows):

var deleteRows = function () {
    Ext.Msg.confirm(
        'Delete Rows', 'Are you sure?',
        function(btn) {
            if (btn == 'yes') {
                var hh = Ext.getCmp('gg').deleteSelected();
                ajax({
                    //action and controller
                    url: '@Url.Action( "Publisher", "Delete")',
                    data: { "Id": Id },
                    type: 'POST',
                    dataType: 'json',
                });
            }
        });
};

由以下按钮的处理程序调用:

X.Button().ID("bntdelete").Text("delete").Icon(Icon.Delete).Handler("deleteRows();"),

它根本没有用这种方式!如何从 JavaScript 函数从客户端移动到服务器端?

4

2 回答 2

0

希望您现在已经解决了这个问题,但是在您的 ajax 调用中,您将类型定义为 post,但是您在控制器上显示的内容被设置为默认获取。你需要添加

[HttpPost]
public JsonResult Delete(int id)...

到你的控制器

于 2013-12-24T18:36:53.847 回答
0

[Direct Method]通常从您使用的 js调用服务器端App.direct.<Method>();

于 2013-07-16T09:06:03.133 回答