@foreach (EmailSubscription es in Model)
   {

if(true){

<div class="onoffswitch">                     
        <input type="checkbox" checked class="onoffswitch-checkbox" name="onoffswitch_1" id="onoffswitch_1">
        <label class="onoffswitch-label" style="border-radius:23px;" name="onoffswitch_1" for="onoffswitch_1">
            <span class="onoffswitch-inner"></span>
            <span class="onoffswitch-switch" style="width:24px;border-radius:12px;"></span>
         </label>
 </div>

}

else

{

<input type="checkbox"  class="onoffswitch-checkbox" name="onoffswitch_1" id="onoffswitch_1">
        <label class="onoffswitch-label" style="border-radius:23px;" name="onoffswitch_1" for="onoffswitch_1">
            <span class="onoffswitch-inner"></span>
            <span class="onoffswitch-switch" style="width:24px;border-radius:12px;"></span>
         </label>

}

}

js中对多个onoffswitch-switch 按钮 进行数组形式的赋值

<script type="text/javascript">

$(document).ready(function(){

var active= new Array();
        var num= new Array();
        var i = 0;
        $("label[name^='onoffswitch_']").on('click',function (e) {

var id = $(this).attr("name").split("_")[1];
            var onswitch= document.getElementById("onoffswitch_" + id).checked;
            if (onswitch)
            {
                active[i] = "false";
            }
            else
            {
                active[i] = "true";
            }
            num[i] = id;
            i++;
        });

$("#btnSave").click(function () {

if (active.length>0 && num.length>0)
            {
                $(".ajax-loader").show();

$.ajax({
                    url: ' ',
                    traditional: true,    //阻止深度序列化,提交时后台处理才能接收到数组值。默认为 false,提交数组必须为true
                    data:
                    {
                        active: active,
                        num: num
                    },
                    complete: function () {
                        $(".ajax-loader").hide();
                    }
                });
            }
        });

});

</script>

c# 里:control里数组接受和处理,接收数组, 避免未修改时更新数据库

public ActionResult SaveSubscriptions(string[] active, string[] num)
        {
            bool Isonline = false;
            List<Num> list = _numService.GetNumByCustomerID(logginUser.UserID).ToList();
            if (list.Count>0)
            {
                for (int i = 0; i < IsOnline.Length; i++)
                {               
                    var num = new Guid(num[i]);
                    num result = list.Where(a => a.ID == num).FirstOrDefault();
                    if(result.active != Boolean.Parse(active[i]))
                    {
                        if (active[i] == "true")
                        {
                            active = true;
                        }
                        else
                        {
                           active = false;
                        }

list.Add(result);
                        active= true;
                    }
                }
            }
            if (active)
            {
                _numService.UpdateNum(list);
            }   
           
            return RedirectToAction("Index");
        }

最新文章

  1. Scrum Meeting 13-20151221
  2. MyBatis_Generator的使用(实践)
  3. 关于C# winform中使用pictureBox显示大红叉的原因
  4. org.springframework.web.HttpRequestMethodNotSupportedException: Request method &#39;PUT&#39; not supported
  5. Java创建Web项目
  6. 菜鸟学Linux命令:find命令 查找文件
  7. POJ2451 Uyuw&#39;s Concert(半平面交)
  8. 33条C#、.Net经典面试题目及答案
  9. Android中多表的SQLite数据库(译)
  10. 你真的用上keepalive了吗
  11. Java设计模式(三)原型模型 适配器型号
  12. dubbo+zookeeper伪集群配置
  13. Maven Install指令构建时出现找不到符号
  14. Ubuntu 共享 转载
  15. pyqt pyside 设置窗口关闭时删除自身
  16. 使用Visual Studio Team Services敏捷规划和项目组合管理(四)——冲刺计划和任务板
  17. ToolBar样式颜色,图标设置
  18. Spring ActiveMQ 整合(三): 确认机制ACK(收到消息后,应该有一个回应也就是确认答复)
  19. 经典的sql语句,将返回结果合并为一个字符串
  20. 点击图片查看大图(纯js)

热门文章

  1. python中namedtuple介绍
  2. Material使用01 侧边栏MdSidenavModule、工具栏MdTollbarModule
  3. jenkins+github持续集成中的坑
  4. 八皇后問題 (C語言递归實現 回溯法)
  5. android代码混淆笔记
  6. Python 项目实践一(外星人入侵小游戏)第三篇
  7. linux系统安全及应用
  8. 知乎APP---案例分析
  9. spring boot + druid + 封装JdbcTemplate
  10. 《程序设计语言&mdash;&mdash;实践之路【PDF】下载