在使用與服務器側數據劍術樹狀存在這樣的問題,而在MVC結合數據劍道TreeView的序列不包含任何元素錯誤
我的控制器操作是:
public ActionResult DayPart(long storeid)
{
IEnumerable<TreeViewMapModel> objDaypart = from item in new DayPartService().GetAll().ToList()
select new TreeViewMapModel
{
Id = item.Id,
Name = item.Name,
Items = (from map in new DayPartMappingService().GetByStoreId(storeid)
where item.Id == map.DayPartId
select new MasterModel() { Id = int.Parse(map.SourceId), Name = map.SourceLabel }).ToList(),
};
var ret = objDaypart.Select(x => new TreeViewMapModel
{
HasChildren = x.Items.Count() > 0,
Id = x.Id,
Items = x.Items ?? Enumerable.Empty<MasterModel>(),
Name = x.Name
});
@ViewBag.storename = new StoreService().GetById(storeid).Name;
return View(ret);
}
並在視圖
@model IEnumerable<Apis.Web.MvcPortal.Areas.Setups.Models.TreeViewMapModel>
@(Html.Kendo().TreeView()
.Name("right-treeview")
.BindTo(Model.ToList(), (Kendo.Mvc.UI.Fluent.NavigationBindingFactory<TreeViewItem> mappings) =>
{
mappings.For<Apis.Web.MvcPortal.Areas.Setups.Models.TreeViewMapModel>(bound => bound.ItemDataBound((node, structure) =>
{
node.HasChildren = structure.HasChildren;
node.Id = structure.Id.ToString();
node.Text = structure.Name;
})
.Children(structure => structure.Items));
})
)
但是我得到的錯誤序列中不包含任何元素。任何人都可以告訴我做錯了什麼。
我的堆棧跟蹤是: 在System.Linq.Enumerable.First [TSource](IEnumerable的1 source) at Kendo.Mvc.UI.NavigationItemContainerExtensions.Bind[TNavigationItem](TNavigationItem component, Object dataItem, NavigationBindingFactory
1廠) 在Kendo.Mvc.UI.NavigationItemContainerExtensions.Bind [TNavigationItem](TNavigationItem分量,對象的DataItem,NavigationBindingFactory 1 factory) at Kendo.Mvc.UI.NavigationItemContainerExtensions.BindTo[TNavigationItem](INavigationItemContainer
1組件,IEnumerable dataSource,Action 1 factoryAction) at Kendo.Mvc.UI.Fluent.TreeViewBuilder.BindTo(IEnumerable dataSource, Action
1 factoryAction) at d:\ APISBI_MVC \ APISBI \ Main \ SRC \ Apis.Web.MvcPortal \ Areas \ Setups \ Views \ Mapping \ DayPart.cshtml中的ASP._Page_Areas_Setups_Views_Mapping_DayPart_cshtml.Execute() line 47 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBa se.ExecutePageHierarchy(WebPageContext pageContext,TextWriter writer,WebPageRenderingBase startPage) at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext,TextWriter writer,Object instance) at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext,TextWriter作者) at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext,ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker。 <> C_ DisplayClass1a.b _17() 在System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter濾波器,ResultExecutingContext preContext,Func`1續)
預先感謝。
TreeViewMapModel是一個ViewModel – Ni3