删除记录jquery flexigrid c#的确认框

本文关键字:确认 flexigrid 记录 jquery 删除 | 更新日期: 2023-09-27 18:28:36

我通过从c#控制器返回json格式的记录来填充jquery flexigrid。然而,我面临着一个小问题。我添加herf列是为了删除特定的记录。它运行良好,但在删除之前我找不到确认的方法。下面是我的c#代码,它将记录返回到flexigrid。

C#控制器代码段

    private JsonResult CreateFlexiJson(IEnumerable<user> items, int page, int total)
    {
        var CurentsessionUser = Session["sessionUserId"].ToString();
        List<Object> rows = new List<Object>();
        foreach (var item in items)
        {
            rows.Add(new
            {
                id = item.id,
                cell = new string[] {                   
                item.msisdn,
                item.pin,
                item.subtype,
                CurentsessionUser =="csagent"?"":String.Format("<a href=" + "'" + "ChangePin?subno=" + item.msisdn + "'" + ">Change Pin</a>"),
                CurentsessionUser =="csagent"?"":String.Format("<a href=" + "'" + "Delete?subno=" + item.msisdn + "'" + ">Delete</a>")              
            }
            });
        }
        var result = new { page = page, total = total, rows = rows };
        return Json(result);
    }
    public ActionResult Delete(string subno)
    {
        try
        {
            wmas_subsEntities entitymodel = new wmas_subsEntities();
            var customer = from p in entitymodel.users where p.msisdn == subno select p;
            if (customer.ToList().Count > 0)
            {
                entitymodel.users.Remove(customer.First());
                entitymodel.SaveChanges();                    
            }
            //return Json("Successfully deleted the user registeration");
            return View("Index");
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

查看

    $('#CustomerList').flexigrid({
        dataType: 'json',
        colModel: [
            {
                display: 'Subscriber No.',
                name: 'msisdn',
                width: 100,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Pin Code',
                name: 'pin',
                width: 100,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Postpaid/Prepaid',
                name: 'subtype',
                width: 100,
                sortable: true,
                align: 'left'
            },
            {
                display: '',
                name: '',
                width: 100,
                sortable: true,
                align: 'left'
            },
            {
                display: '',
                name: '',
                width: 100,
                sortable: true,
                align: 'left'
            }

        ],
        title: 'Customer',
        useRp: true,
        rp: 15,
        width: 600,
        height:400,
        singleSelect: true
    });

删除记录jquery flexigrid c#的确认框

CreateFlexiJson操作中,在行下方更改

CurentsessionUser =="csagent"?"":String.Format("<a href=" + "'" + "Delete?subno=" + item.msisdn + "'" + ">Delete</a>")              

CurentsessionUser =="csagent"?"":String.Format("<a href='javascript:void(0)' onclick='deleteSubscriber('"" + item.msisdn + "'")'>Delete</a>")      

并添加javascript function deleteSubscriber

function deleteSubscriber(subno) {
    if (confirm("Are you sure to delete Subscriber (No. = " + subno + ")")) {
        location.href = "Delete?subno=" + subno;
    }
}