我創建了一個MVC應用程序,該應用程序使用ViewBag傳遞數據來使用多個實體填充視圖。無法使用ViewBag填充Kendo網格而不是模型
但是我似乎無法獲得劍道UI電網從ViewBag來填充和我不斷收到以下運行時錯誤:
CS0452: The type 'System.Collections.Generic.KeyValuePair<string,string>' must be a reference type in order to use it as parameter 'T' in the generic type or method 'Kendo.Mvc.UI.Fluent.WidgetFactory.Grid<T>(System.Collections.Generic.IEnumerable<T>)'
我相信我遇到的問題是此行的代碼:
@(Html.Kendo().Grid((Dictionary<string,string>)ViewBag.ApplicationStatuses)
完整剃刀代碼如下:
@{
ViewBag.Title = "TestView";
}
<h2>TestView</h2>
@(Html.Kendo().Grid((Dictionary<string,string>)ViewBag.ApplicationStatuses).Name("UserDetails").Columns(c =>
{
c.Bound(ud => ud.FullName);
c.Bound(ud => ud.JobTitle);
c.Bound(ud => ud.Department);
c.Bound(ud => ud.Email);
c.Template(
@<text>
@Html.ActionLink("User Details", "UserDetails", "User", new { userName = item.UserName }, null)
</text>
);
})
)
我的控制器:
public ActionResult TestView(string userName)
{
Dictionary<string, string> statuses = new Dictionary<string, string>();
foreach (KeyValuePair<Application.Applications, IUser> entry in Application.UserMap)
{
IUser user = entry.Value;
statuses.Add(entry.Key.ToString(), entry.Value.GetUserStatus(userName));
}
ViewBag.ApplicationStatuses = statuses;
ViewBag.UserName = userName;
return View();
}
爲什麼我有這個問題,有什麼解決的辦法是任何人可以解釋一下嗎?
任何幫助將不勝感激。
我同意我沒有改變那部分代碼,但我會編輯它,但我沒有獲得智能,所以我不知道IEnumerable應該做什麼。 – SlipperyBalmain 2014-10-01 08:28:28
我已經編輯了我的答案,嘗試並防止混淆這一點,但我仍然沒有在這裏正確的邏輯。你能建議嗎? – SlipperyBalmain 2014-10-01 08:30:46
編輯我的答案 – 2014-10-01 11:52:38