2
我試圖創建一個自定義屬性來控制自定義HTML幫助程序對象中的格式。我的自定義選擇器類的源代碼是(代碼是從http://forums.asp.net/t/1649193.aspx/1/10)。MVC3 - 在html.helper中獲取數據屬性
public static MvcHtmlString DdUovFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList, string optionLabel, IDictionary<string, object> htmlAttributes)
{
ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
var m = expression.Body.GetType();
IDictionary<string, object> validationAttributes = htmlHelper
.GetUnobtrusiveValidationAttributes(ExpressionHelper.GetExpressionText(expression), metadata);
if (htmlAttributes == null)
htmlAttributes = validationAttributes;
else
htmlAttributes = htmlAttributes.Concat(validationAttributes).ToDictionary(k => k.Key, v => v.Value);
return SelectExtensions.DropDownListFor(htmlHelper, expression,
selectList, optionLabel, htmlAttributes);
}
我的自定義屬性是
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property |
AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
public class LookUpAttribute : Attribute
{
public LookUpAttribute(Type providerName)
{
this.providerName = providerName;
}
protected ILookup providerName;
}
我的問題是,我無法弄清楚如何找回我的自定義屬性在HTML輔助方法。