【问题标题】:why checkbox is hidden even using my htmlhelper? [duplicate]为什么即使使用我的 htmlhelper 也隐藏了复选框? [复制]
【发布时间】:2018-05-01 14:17:51
【问题描述】:

我已经阅读了很多关于隐藏字段回合复选框的链接,我决定使用自定义 htmlhelper,但目前,当我删除 type="checkbox" 中的复选框字时,我在页面中看不到复选框,它显示为文本框我认为它对名称复选框的控件类型很敏感。

更新: 我没有任何带有隐藏值的输入 Picture

 public static class HelperUI
{
    public static MvcHtmlString CheckBoxSimpleFor<TModel>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, bool>> expression, object htmlAttributes)
    {
        string checkBoxWithHidden = htmlHelper.CheckBoxFor(expression, htmlAttributes).ToHtmlString().Trim();
        string pureCheckBox = checkBoxWithHidden.Substring(0, checkBoxWithHidden.IndexOf("<input", 1));
        return new MvcHtmlString(pureCheckBox);
    }
}


 <div class="col-md-6">
     <div class="form-group row">
         <label class="text-right col-md-3">وضعیت</label>

         <div class="col-md-9">

             @Html.CheckBoxSimpleFor(model => model.Status, new { @class = "form-control filled-in" })


         </div>
     </div>
 </div>

【问题讨论】:

  • position: absolute; left: -9999px; opacity: 0
  • CSS sn-p 是您无法看到复选框的原因。它不在屏幕上,不透明度为零。如果您查看开发人员工具中的 CSS 检查器,您可以看到 CSS 处于活动状态。
  • @serpent5,是的,它确实对我有用,但我稍微改变了样式。 '位置:未设置!重要;' '不透明度:1 !important;'

标签: c# asp.net-mvc checkbox html-helper


【解决方案1】:

嗨@joe,如果您使用引导程序进行 html 设计,那么该复选框将显示为隐藏,因为引导程序复选框 html sysntax 或设计不同,请根据它进行更改

  <div class="checkbox">
     <input id="checkbox1" type="checkbox">
     <label for="checkbox1">
      Default
  </label>
       </div>

这是在bootstrap中设计sysntax或代码的复选框,所以你需要按照自己的方式进行更改

    <div class="checkbox col-md-9">
         @Html.CheckBoxSimpleFor(model => model.Status, new { @class = " filled-in" })
    </div>

【讨论】:

    猜你喜欢
    • 2011-06-03
    • 2023-01-02
    • 2019-04-07
    • 2021-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-03
    • 2016-05-03
    相关资源
    最近更新 更多