I've created an extension method which is supposed to provide table header text for a table containing a collection of items of type IList<T>
. Though, the compiler says that TModel cannot be inferred from usage, however, for me it is obvious if the type argument constraint says that TListModel
is an IList<TModel>
, then TModel
could indeed be inferred.
public static MvcHtmlString HeaderFor<TListModel, TModel, TValue>(this HtmlHelper<TListModel> listViewModel, Expression<Func<TModel, TValue>> expression)
where TListModel : IList<TModel>
TListModel
is say List<Product>
, so TModel
is Product
, and as such, I'd like to use the HtmlHelper like this:
<th scope="col" class="azonosito">
@Html.HeaderFor(x => x.Price)
</th>
I now have to use it like this, which is so awkward:
<th scope="col" class="azonosito">
@Html.HeaderFor((Product x) => x.Price)
</th>