码迷,mamicode.com
首页 > Web开发 > 详细

MVC视图中扩展helper(泛型绑定Model)

时间:2019-11-28 19:29:52      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:Edito   col   class   turn   泛型   sage   pre   public   attr   

    @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)

MVC视图中扩展helper(泛型绑定Model)

标签:Edito   col   class   turn   泛型   sage   pre   public   attr   

原文地址:https://www.cnblogs.com/nirvanan/p/11951868.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!