23 Kasım 2012 Cuma

mvc de $.ajax() ile multi delete


function f_MultiDelete()
{
if ($(".chList").size() > 0) {
            var IDS = [];

            $(".chList").each(function (i) {
                if ($(this).attr('checked') == "checked" && $(this).attr('name') == "checkDelete") {
                    var ID = $(this).attr("vl");
                    IDS.push(ID);
                }
            });
            if (IDS.length > 0) {
                $.ajax({
                    type: "POST",url: Path,

                    traditional:true,
                    dataType:"json",
                    data: { 'IDList': IDS },
                    success: function (data) {
                        alert(data);
                    }
                });
            }
        }
}

<input name="checkDelete" class="chList" vl="4" type="checkbox" />
<input name="checkDelete" class="chList" vl="3" type="checkbox" />
<input name="checkDelete" class="chList" vl="2" type="checkbox" />
<input name="checkDelete" class="chList" vl="5" type="checkbox" />

<div onclick="f_MultiDelete('/Admin/AGaleri/MultiDelete/')" class="btn btn-primary">Seçilileri Sil </div>




public ActionResult MultiDelete(IEnumerable<string> IDList)
{
    //IDList parametresinden seçili ID lere ulaşabilirsiniz.
}