Jquery easyui datagrid 刪除多行問題

來源:互聯網
上載者:User

標籤:

http://www.cnblogs.com/Dtscal/archive/2012/07/04/2576639.html

最近模仿了劉冬大哥的<開源架構完美組合之Spring.NET + NHibernate + ASP.NET MVC + jQuery + easyUI 中英文雙語言小型企業網站Demo>之後發現一個問題就是前台datagrid如果刪除多行之後,然後再編輯就不能進入對應的行資訊.:

前台選擇多行->刪除

刪除成功

 

這裡變成了刪除的編碼,

 

前台代碼

<script type="text/javascript">

$(function () {

$(‘#test‘).datagrid({

title: ‘風格資訊‘,

iconCls: ‘icon-save‘,

fit: true,

nowrap: false,

striped: true,

//collapsible: true,

url: ‘/GenerManage/LoadAllByPage/‘,

sortName: ‘GenreId‘,

remoteSort: false,

idField: ‘GenreId‘,

frozenColumns: [[

     { field: ‘ck‘, checkbox: true }

                ]],

columns: [[

             { field: ‘GenreId‘, title: ‘編碼‘, width: ‘80‘, align: ‘center‘ },

                    { field: ‘Name‘, title: ‘名稱‘, width: ‘200‘, align: ‘left‘ },

{ field: ‘Desctiption‘, title: ‘描述‘, width: ‘350‘, align: ‘left‘ }

                ]],

pagination: true,

rownumbers: true,

toolbar: [{

id: ‘btnadd‘,

text: ‘添加‘,

iconCls: ‘icon-add‘,

handler: function () {

this.href = ‘/GenerManage/View/‘;

}

}, {

id: ‘btnupdate‘,

text: ‘修改‘,

iconCls: ‘icon-save‘,

handler: function () {

var rows = $(‘#test‘).datagrid(‘getSelected‘);

if (rows) {

this.href = "/GenerManage/View/" + rows.GenreId;

}

else {

$.messager.alert(‘提示‘, ‘請選擇要修改的資料‘);

return;

}

}

}, ‘-‘, {

id: ‘btncut‘,

text: ‘刪除‘,

iconCls: ‘icon-cut‘,

handler: function () {

//擷取表格選擇行

var rows = $(‘#test‘).datagrid(‘getSelections‘);

//判斷是否選擇行

if (!rows || rows.length == 0) {

$.messager.alert(‘提示‘, ‘請選擇要刪除的資料!‘, ‘info‘);

return;

}

 

var parm;

//迴圈給提交刪除參數賦值(音樂風格編碼)

$.each(rows, function (i, n) {

if (i == 0) {

parm = "idList=" + n.GenreId;

} else {

parm += "&idList=" + n.GenreId;

}

});

$.messager.confirm(‘提示‘, ‘是否刪除選中資料?‘, function (r) {

if (!r) {

return;

}

//提交

$.post(‘/GenerManage/Delete/‘, parm,

function (msg) {

if (msg.IsSuccess) {

$.messager.alert(‘提示‘, msg.Message, ‘info‘, function () {

//重新載入當前頁

$(‘#test‘).datagrid(‘reload‘);

});

} else {

$.messager.alert(‘提示‘, msg.Message, ‘info‘)

}

});

});

}

}]

});

var p = $(‘#test‘).datagrid(‘getPager‘);

if (p) {

$(p).pagination({

onBeforeRefresh: function () {

alert(‘before refresh‘);

}

});

}

});

</script>

後台代碼

//顯示建立或者修改資訊

public ActionResult View(int? id)

{

Genre g =

(from gener in msdb.Genre

where gener.GenreId == id

select gener).FirstOrDefault();

if (g == null)

g = new Genre();

return View(g);

}

[HttpPost]

public ActionResult Delete(IList<int> idList)

{

//判斷判斷是否刪除多行資料

if (idList.Count > 1)

{

foreach (int i in idList)

{

var gener =

from g in msdb.Genre

where g.GenreId == i

select g;

msdb.Genre.DeleteAllOnSubmit(gener);

}

}

else

{

var gener =

from g in msdb.Genre

where g.GenreId == idList.First()

select g;

msdb.Genre.DeleteAllOnSubmit(gener);

}

//這裡刪除多條記錄的時候提示varchar-int失敗所以用上面的辦法

// msdb.Genre.DeleteAllOnSubmit(idList.Cast<Genre>().ToList());

msdb.SubmitChanges();

return Json(new { IsSuccess = true, Message = "刪除成功" });

}

Jquery easyui datagrid 刪除多行問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.