2014-10-31 39 views
0

我通過從c#控制器返回json格式的記錄來填充jquery flexigrid。但是我面臨的一點問題。我正在添加herf列以刪除特定記錄。它工作正常,但我不能找到方式來確認它之前刪除它。下面是我的C#代碼,它返回記錄到flexigrid。刪除記錄jquery flexigrid c的確認框#

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 
    }); 

回答

0

CreateFlexiJson動作,下面線變化

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

TO

​​

並添加JavaScript function deleteSubscriber

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