我正在使用將數據和元數據包裝在單個屬性中的遺留模型。對於這個問題的目的,假設該接口是:有沒有辦法用自定義邏輯來包裝Html.CheckboxFor,Html.TextboxFor等方法?
pubic interface ILegacyCheckbox
{
bool Value { get; set; }
bool Editable { get; set; }
}
我想用我自己的包裹CheckBoxFor()擴展方法,
public static MvcHtmlString LegacyCheckboxFor<TModel>(
this HtmlHelper<TModel> html,
Expression<Func<TModel, ILegacyCheckbox>> expression)
{
// wrap html.CheckBoxFor() method here by extracting the Value
// property and check if Editable is false, in which case add
// an htmlAttribute of "disabled=true"
}
有沒有辦法做這樣的事情?我會在哪裏開始?
任何幫助,將不勝感激,
謝謝,
亞歷
謝謝,工作! – afeygin 2011-06-10 16:18:34
我是否需要使用html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName()來包裝parameterName以確保它在foreach循環中有效? – afeygin 2011-06-10 16:20:38