Don't bind the model using viewbag. Heres how you could it from the server.
@(Html.Kendo().DropDownListFor(x => x.FromOpportunity)
.Name("OpportunityDDL")
.DataTextField("OpportunityName")
.DataValueField("OpportunityId")
.DataSource(source => {
source.Read(read =>
{
read.Action("GetOpportunityListByAccount", "CrmIntegration")
.Data("OnAdditionalData");
})
. ServerFiltering(true);
})
.HtmlAttributes( new { style = "margin-left:13px; width: 275px;" })
Controller
This is kind've pseudo coded but basically return a Json list
List<OpportunityViewModel> oppVMList = new List<OpportunityViewModel>();
var oppList = new OrderManager().GetOpportunitiesByAccount(Id);
foreach (var op in oppList)
{
OpportunityViewModel opvm = new OpportunityViewModel();
opvm.OpportunityId = op.OpportunityId;
opvm.OpportunityName = op.OpportunityName;
oppVMList.Add(opvm);
}
return Json(oppVMList , JsonRequestBehavior.AllowGet);
And to refresh the ddl
var opportunity = $("#OpportunityDDL").data("kendoDropDownList");
opportunity.dataSource.read({ Id: advertiserId });
your parameter name must be Id
ANy questions just ask :)
Here's my JS function for OnAdditionalData, basically it goes to this function to get the parameter before reading the controller method GetOpportunityListByAccount
function OnAdditionalData() {
var dataItem = $("#Advertisers").data("kendoMultiSelect").value();
return {
//call would not work when expecting a Guid,
//now it expects a string
Id: "" + dataItem
};
}