So I packed some query results in a viewdata statement.
I can verify the correct number of results are put into the viewdata object in the view with this directive:
@foreach (var action in (List<LemonadeTrader.Models.Message>)ViewData["messages"]) {
When I try to display the results:
@Html.DisplayFor( (LemonTrader.Models.Message)action.msg) // action.msg should be of type string
It says it couldn’t convert string to LemonTrader.Models.Lemon.
When I cast it as:
@Html.DisplayFor( (string)action.acidity)
It says:
The type arguments for method
‘System.Web.Mvc.Html.DisplayExtensions.DisplayFor(System.Web.Mvc.
HtmlHelper,
System.Linq.Expressions.Expression>)’
cannot be inferred from the usage. Try
specifying the type arguments
explicitly.
Not casting it at all doesn’t work either.
How do I cast the result?
This worked: