public static MvcHtmlString CheckBoxListFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression) where TValue : bool
and bool
is not valid. Boolean
is also not valid. What can I use? TValue must be bool
?
edit: I am writing HTMLHELPER for mvc3 and later onis used as html.CheckBoxFor(expression)
so TValue
must be generic
如果TValue
必须为bool
,则它不是通用的。
public static MvcHtmlString CheckBoxListFor<TModel>(this HtmlHelper<TModel> html, Expression<Func<TModel, bool>> expression)
然后只需删除TValue
类型参数,并将其替换为bool
:
public static MvcHtmlString CheckBoxListFor<TModel>(this HtmlHelper<TModel> html, Expression<Func<TModel, bool>> expression)
From your comments, it looks to me like you need two different overloads:
public static MvcHtmlString CheckBoxListFor<TModel>(this HtmlHelper<TModel> html,
Expression<Func<TModel, bool>> predicateExpression)
and
public static MvcHtmlString CheckBoxListFor<TModel, TValue>(this HtmlHelper<TModel> html,
Expression<Func<TModel, TValue>> expression)
Internally, you can share the inner implementation and add what you need.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.