我有自己的html helper扩展,我这样使用它。
<%=Html.LocalizableLabelFor(model => model.Reason_ID, Register.PurchaseReason) %>声明是这样的。
public static MvcHtmlString LocalizableLabelFor<T>(this HtmlHelper<T> helper, Expression<Func<T, object>> expr, string captionValue) where T : class {
return helper.LocalizableLabelFor(ExpressionHelper.GetExpressionText(expr), captionValue);
}但是当我在调试器中打开它时,expr.Body.ToString()会显示Convert(model.Reason_ID)。但是model.Reason_ID应该。这是一个大问题,因为ExpressionHelper.GetExpressionText(expr)返回空字符串。
这是什么奇怪的魔法?我怎样才能摆脱它?
发布于 2010-05-29 22:01:13
问题出在你的Func泛型类型。用Func<T,S>替换Func<T,object>,你就可以开始工作了:
public static MvcHtmlString LocalizableLabelFor<T,S>(this HtmlHelper<T> helper, Expression<Func<T, S>> expr, string captionValue) where T : class
{
// ... code ...
}https://stackoverflow.com/questions/2935261
复制相似问题