我们是五月的花海 , 用青春拥抱|

兴想事成

园龄:12年10个月粉丝:25关注:97

数据批量删除_从页面js到后台数据库

   LayUI   批量选择的 ,然后操作

复制代码
 batchdel: function () {
                    var checkStatus = table.checkStatus('LAY-gridview')
                        , checkData = checkStatus.data; //得到选中的数据
                    if (checkData.length === 0) {
                        return layer.msg('请选择数据');
                    }

                    //var dataId = JSON.stringify(checkData[0].Id);
                    // layer.alert(JSON.stringify(checkData[0].Id));
                    var pStr = "";
                    for (var i = 0; i < checkData.length; i++) {  
                        pStr = pStr + JSON.stringify(checkData[i].Id)+",";
                    }  
                  pStr=  pStr.substring(0, pStr.length - 1);
                 
                
                 layer.confirm('确定删除该行数据吗?', function (index) {

                        //向服务端发送删除指令, 批量删除
                        var changeUrl = '<%= Url.Action("DeleteByIds", "UrlList",new {r=DateTime.Now.Ticks})  %>';

                        $.post(changeUrl, { ids: pStr }, function (reData) {
                            if (reData.success) {
                              
                                table.reload('LAY-gridview');
                                layer.msg('已删除');
                                 layer.close(index);
                            } else {
                                layer.msg("删除失败!");
                            }

                        });
                        
                    });
复制代码

后台方法

复制代码
  public JsonResult DeleteByIds()
        {
            UrlListBLL listBLL = new UrlListBLL();
            try
            {
                string idStr = Request.Form["ids"];
                bool result = false;
                string[] sNums= idStr.Split(',').ToArray();
                if (sNums.Length > 0)
                {
                    int[] ids = Array.ConvertAll(sNums, int.Parse);
                    result = listBLL.DeleteByIds(ids);
                }
                var json = new
                {
                    success = result,
                    msg = ""
                };
                return Json(json, JsonRequestBehavior.AllowGet);

            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                if (ex.InnerException != null)
                {
                    msg += ex.InnerException.Message;
                }

                throw ex;
            }
        }
复制代码

批量删除

复制代码
   /// <summary>
        /// 批量删除 
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public bool DeleteByIds(int[]ids)
        {
            bool result = false;
            using (CoolToolDBEntities db = new CoolToolDBEntities())
            {
                foreach (int id in ids)
                {
                    UrlInfo utlInfo = new UrlInfo() { Id=id};
                    db.Entry<UrlInfo>(utlInfo).State = System.Data.EntityState.Deleted;
                }
                result = db.SaveChanges() > 0;
            }

            return result;
        }
复制代码

 

posted @   兴想事成  阅读(423)  评论(2编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 Good-bye My Loneliness ZARD
  2. 2 Say OK Vanessa Hudgens
  3. 3 All The Love In The World The Corrs
  4. 4 Adesso E Fortuna ~炎と永遠~ 加藤いづみ
Say OK - Vanessa Hudgens
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : BIRGISSON, ARNTHOR/KOTECHA, SAVAN

作曲 : Savan Kotecha/Arnthor Birgisson

Vanessa Hudgens - Say OK

Album: V

You are fine

You are fine

You are fine

You are fine

You are sweet

But I'm still a bit naive with my heart

When you're close I don't breathe

I can't find the words to speak

I feel sparks

But I don't wanna be into you

If you are not looking for true love, oh oh

No I don't wanna start seeing you

If I can't be your only one

So tell me when it's not alright

When it's not ok

Will you try to make me feel better?

Will you say alright? (say alright)

Will you say ok? (Say ok)

Will you stick with me through whatever?

Or run away

(Say that it's gonna be alright)

(That it's gonna be ok)

Say OK

When you call I don't know

If I should pick up the phone every time

I'm not like all my friends

Who keep calling up the boys, I'm so shy

But I don't wanna be into you

If you don't treat me the right way

See I can only start seeing you

If you can make my heart feel safe (feel safe)

When it's not alright

When it's not ok

Will you try to make me feel better?

Will you say alright? (say alright)

Will you say ok? (Say ok)

Will you stick with me through whatever?

Or run away

(Say that it's gonna be alright)

(That it's gonna be ok)

(Don't run away, don't run away)

Let me know if it's gonna be you

Boy, you've got some things to prove

Let me know that you'll keep me safe

I don't want you to run away so

Let me know that you'll call on time

Let me know that you won't be shy

Will you wipe my tears away

Will you hold me closer

When it's not alright

When it's not ok

Will you try to make me feel better

Will you say alright? (say alright)

Will you say ok? (Say ok)

Will you stick with me through whatever?

Or run away

(Say that it's gonna be alright)

(That it's gonna be ok)

Say OK

(Don't run away, don't run away)

(Say that it's gonna be alright)

(That it's gonna be ok)

(Don't run away)

Will you say OK

(Say that it's gonna be alright)

(That it's gonna be ok)

(Don't run away)

You are fine

You are fine