0

TextBoxFor を拡張する方法を知っています:

public static MvcHtmlString TextBoxFor<TModel, TValue>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TValue>> expression, object htmlAttributes)
        {
            MvcHtmlString html = default(MvcHtmlString);
            RouteValueDictionary routeValues = new RouteValueDictionary(htmlAttributes);         
            html = System.Web.Mvc.Html.InputExtensions.TextBoxFor(htmlHelper, expression, routeValues);
            return html;
        }

TextAreaFor についても同じことをしたいのですが、残念ながらSystem.Web.Mvc.Html.InputExtensionsには TextAreaFor メソッドが含まれていません。どうすればこれを解決できますか?

4

2 に答える 2

2

docを参照してください、それはTextAreaExtensions静的クラスにあります

return System.Web.Mvc.Html.TextAreaExtensions.TextAreaFor(htmlHelper, expression, routeValues);

あるいは単に

return htmlHelper.TextAreaFor(expression, routeValues);

ちなみに、3 番目の引数は (TextBoxFor のように) aIDictionary<string, Object> htmlAttributesであり、RouteValues とは関係ありません。

RouteValueDictionary実装しているので機能しIDictionary<string, Object>ていますが、あなたの議論は紛らわしいです。

于 2013-08-26T16:24:08.157 に答える
1

プロパティにタグを付けて[System.ComponentModel.DataAnnotations.DataType(DataType.MultilineText)]から使用EditorForすると、必要な結果が得られるはずです。

public class SomeClass
{
    [DataType(DataType.MultilineText)]
    public string Name { get; set; }
}

@Html.EditorFor(x => x.Name)
于 2013-08-26T16:27:53.877 に答える