I'm working with the System.Web.Helpers.WebGrid
in an ASP.NET MVC 3 Razor project, and I'm having trouble understanding why the format parameter for a WebGridColumn
is a Func<dynamic, object>
.
If I create a column like this...
grid.Column(
format: x => string.Format("{0:d}", x.StartDate)
);
...I don't get strong typing on the StartDate property. If I try to get around it like this...
grid.Column(
format: (MyObjectType x) => string.Format("{0:d}", x.StartDate)
);
...I'm told at runtime that my lambda can't be cast to a Func<dynamic, object>
. Is there some way I can use a non-dynamic lambda here? Even if it's just <object, object>
?
(I'm in .NET 4.0, and Func<in T, out TResult>
is supposed to be contravariant on T, but I'm confused about how covariance and contravariance work with dynamic.)
StartDate
doesn't exist at runtime. Six of one, half a dozen of the other. But as it is, if I change theStartDate
property to, say,InitialDate
, this MVC view will break at runtime; I won't be able to detect it even if I enable building views at compile time. – Cthrine