zoukankan      html  css  js  c++  java
  • ASP.NET MVC CheckBoxFor的int to bool

    当我们使用CheckBoxFor类型需要使用bool ,可以将 int转换成bool

                   <div class="form-group">
                        <label class="col-md-3 control-label">选项</label>
                        <div class="col-md-4">
                            @Html.CheckBoxFor(m => m.EnabledValue) 有效
                            @Html.CheckBoxFor(m => m.IsUnfoldValue) 展开
                            @Html.CheckBoxFor(m => m.AllowEditValue) 允许编辑
                            @Html.CheckBoxFor(m => m.AllowDeleteValue) 允许删除
                            <span class="help-block">
                            </span>
                        </div>
                    </div>

    在实体类添加紫色代码

            /// <summary>
            /// 有效:1-有效,0-无效
            /// </summary>
            public int? Enabled
            {
                set{ _enabled=value;}
                get{return _enabled;}
            }
            public bool EnabledValue
            {
                get { return Enabled == 1; }
                set { Enabled = value ? 1 : 0; }
            }

    修改数据

      public ActionResult Edit(string id)
            {
                ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
                var model = new SAS.Model.BPMS_SysMenu();
                model=bll.GetModel(id);
                if (model != null)
                {
                    ParentDropDownList();  
                    return View(model);
                }
                else
                {
                    return View("404");
                }
            }
    
            [HttpPost, ValidateInput(false)]
            public ActionResult Edit(string id, FormCollection fc)
            {
                var model = bll.GetModel(id);
                if (model != null)
                {
                   
                    UpdateModel(model);  //修改数据
                    bll.Update(model);
                    return RedirectToAction("ModuleList");
                }
                else
                    return View("404");
            }

    数据库里面

    1-有效,0-无效

    使用效果比较好

  • 相关阅读:
    windows 设置nginx开机自启动
    vue js中解决二进制转图片显示问题
    oracle 各种问题
    Nginx安装及配置详解包括windows linux 环境
    AOP-切面是如何织入到目标对象中的
    AOP-通知-笔记
    AOP-方法拦截器-笔记
    JdkDynamicAopProxy-笔记
    Joinpoint继承体系-笔记
    AOP-Pointcut-笔记
  • 原文地址:https://www.cnblogs.com/cube/p/4884670.html
Copyright © 2011-2022 走看看