【问题标题】:Extending InputExtensions in ASP.Net MVC在 ASP.Net MVC 中扩展 InputExtensions
【发布时间】:2012-07-03 07:03:44
【问题描述】:

我的目的是扩展 @Html.TextBoxFor 等方法的功能。我本质上想用一些额外的 HTML 包装生成的标记,其中包含一些逻辑。

现在在我的扩展方法中,我想调用@Html.TextBoxFor 并将其包装起来。我需要参考和使用什么才能让它发挥作用?

【问题讨论】:

    标签: asp.net-mvc-3 razor extension-methods


    【解决方案1】:

    基本上是这样的

    using System;
    using System.Linq.Expressions;
    using System.Web.Mvc;
    using System.Web.Mvc.Html;
    
    namespace Html
    {
        public static class ExtendedInputExtensions
        {
            public static MvcHtmlString ExtendedTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression)
            {
                var original = helper.TextBoxFor(expression);
                return original;
            }
        }
    }
    

    【讨论】:

    • 我还需要添加using System.Web.Mvc.Html;,才能访问原始的TextBoxFor 方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2010-10-29
    • 1970-01-01
    • 2015-02-09
    相关资源
    最近更新 更多