2014-02-17 24 views
0

的数据不会被绑定到剑道下拉列表列表返回形成我的方法 我的下拉数据不mvc4结合剑道下拉列表

@(Html.Kendo().DropDownListFor(model => model.ParentAssetID) 
     .OptionLabel(" ") 
     .Name("ParentAssetID") 
     .DataTextField("AssetName") 
     .DataValueField("AssetId") 
     .SelectedIndex(0)      
     .Text(string.Empty) 
     .DataSource(source => 
     { 
      source.Read(read => 
      { 
       read.Url("../Asset/GetAllAssetsByCompanyId"); 
      }); 
     })) 

我的操作结果

public IEnumerable<AssetDetails> GetAllAssetsByCompanyId() 
    { 
     IList<AssetDetails> _assetSearchlist; 
     using (var client = new HttpClient()) 
     { 
      AssetRepository assetrep = new AssetRepository(); 
      Guid cp = new Guid(Session["CurrentCompanyId"].ToString()); 
      _assetSearchlist = assetrep.GetAllAssetsByCompanyId(cp, "", "", ""); 
      return _assetSearchlist; 
     } 
    } 
+0

我越来越不确定..in下拉 – Karthik

回答

2
public JsonResult GetOpportunityListByAccount(string Id) 
    { 
     Guid ID = new Guid(Id); 
     List<OpportunityViewModel> cpvm = new List<OpportunityViewModel>(); 


     List<CrmOpportunity> crmOppList = new List<CrmOpportunity>(); 

      cpvm = srv.OpportunitySet.Where(z => z.CustomerId.Id == ID).ToList(); 

      foreach (var crm in cpvm) 
      { 
       CrmOpportunity crmOpp = new CrmOpportunity(); 
       crmOpp.Id = crm.Id; 
       crmOpp.Name = crm.Name; 
       crmOppList.Add(crmOpp); 
      } 

      return Json(crmOppList, JsonRequestBehavior.AllowGet); 
    } 


@(Html.Kendo().DropDownListFor(x => x.FromOpportunity)  
    .Name("OpportunityDDL")     
      .DataTextField("Name")    
      .DataValueField("Id")       
      .DataSource(source => { 
       source.Read(read => 
       { 
        read.Action("GetOpportunityListByAccount", "CrmIntegration");       
       }) 
       . ServerFiltering(true); 
      })  

      .HtmlAttributes(new { style = "margin-left:13px; width: 275px;" }) 
    )  

数据访问是一个小截,但是这是你必须要做的

+0

+1这个东西。根据DropDownList上的[docs](http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/helpers/dropdownlist/overview),它需要JSON格式的数据所以它可以实际绑定。 – Stargazer

0
@(Html.Kendo().DropDownListFor(model => model.ParentAssetID) 
     .OptionLabel(" ") 
     .Name("ParentAssetID") 
     .DataTextField("AssetName") 
     .DataValueField("AssetId") 
     .SelectedIndex(0)      
     .Text(string.Empty) 
     .DataSource(source => 
     { 
      source.Read(read => 
        { 
         read.Action("GetAllAssetsByCompanyId", "Asset"); 
        }); 
     })) 

只有一个小的变化,但你试过read.Action?也可以尝试删除以下;

DropDownListFor(model => model.ParentAssetID) 

DropDownListFor<ClassName>() 

只有一个念头代替。