zoukankan      html  css  js  c++  java
  • MVC视图中扩展helper(泛型绑定Model)

        @functions{
            public HelperResult EditBoxFor<TModel, TKey>(HtmlHelper<TModel> html, Expression<Func<TModel, TKey>> expression, bool disabled = false)
            {
                return EditBox(
                    html.LabelFor(expression, htmlAttributes: new { @class = "col-md-3 control-label" }),
                    disabled ? html.EditorFor(expression, new { htmlAttributes = new { @class = "form-control", disabled = "" } })
                        : html.EditorFor(expression, new { htmlAttributes = new { @class = "form-control" } }),
                    html.ValidationMessageFor(expression, "", new { @class = "text-danger" })
                    );
            }
        }
        @helper EditBox(MvcHtmlString label, MvcHtmlString editor, MvcHtmlString validation)
        {
            <div class="form-group">
                @label
                <div class="col-md-9">
                    @editor
                    @validation
                </div>
            </div>
         }

    调用: 

    @EditBoxFor(Html, model => model.Agent, true)

  • 相关阅读:
    338. Counting Bits
    78. Subsets
    MySQL读写分离
    AESEncryption Aes 加密
    LoopBox 用于包装循环的盒子
    ES 服务器 索引、类型仓库基类 BaseESStorage
    一键压缩脚本
    非常好用的一个分组扩展方法
    快递、拆分、合并、优选逻辑
    Git Extensions 使用小结
  • 原文地址:https://www.cnblogs.com/nirvanan/p/11951868.html
Copyright © 2011-2022 走看看