2013-07-18 52 views
0

在使用與服務器側數據劍術樹狀存在這樣的問題,而在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續)

預先感謝。

+0

TreeViewMapModel是一個ViewModel – Ni3

回答

0

當兒童的對象數據類型也沒有轉換爲傳遞給網格的相同類型時,我得到了類似的錯誤。

例如,在我的情況下,來自服務的是一個List,我轉換爲一個更通用的List - 但坐在每個Tag上的孩子仍然是標籤。

我要麼需要一個遞歸函數的子標籤轉換爲OurTreeItemClass或替代,創建一個返回首先這個數據作爲OurTreeItemClass緩解需要在所有這些轉換服務的方法。

相關問題