誰かがHtml.TextBoxForヘルパーを拡張する簡単でわかりやすい例を提供してくれることを願っています。trueの場合にコントロールを読み取り専用にする(サプライズ、サプライズ、サプライズ)ブール値のReadOnlyパラメーターを含めたいと思います。うまくいかなかった例をいくつか見て、次のことを試しましたが、HtmlHelperパラメーターが認識するTextBoxForの唯一の署名は、作成しているものです(usingステートメントがありませんか?) :
public static MvcHtmlString TextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, object htmlAttributes, bool disabled)
{
var values = new RouteValueDictionary(htmlAttributes);
if (disabled)
values.Add("disabled", "true");
return htmlHelper.TextBoxFor(expression, values)); //<-- error here
}
簡単な例が私を正しい軌道に乗せるのに役立つことを願っています。
ありがとう。