所以我在viewdata語句中打包了一些查詢結果。在foreach語句中解包viewdata
我可以確認結果的正確數量被放入可視數據對象在視圖中使用此指令:
@foreach (var action in (List<LemonadeTrader.Models.Message>)ViewData["messages"]) {
當我嘗試以顯示結果:
@Html.DisplayFor((LemonTrader.Models.Message)action.msg) // action.msg should be of type string
它說,它無法將字符串轉換爲LemonTrader.Models.Lemon。
當我投它爲:
@Html.DisplayFor((string)action.acidity)
它說:
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.
不投它在所有也不行。
我該如何施放結果?
我收到此錯誤:「模板只能與字段訪問,屬性訪問,單維數組索引或單參數自定義索引器表達式一起使用。」 – micahhoover 2011-06-01 18:19:53