Hello,
I'm trying to set the value of the cascading dropdownlist, i want to set the value that the model have in the second dropdownlist. The value seems to be set, but only after i first click on the second dropdownlist then i get the right "name" in the list. Anything i'm doing wrong?
I'm trying to set the value of the cascading dropdownlist, i want to set the value that the model have in the second dropdownlist. The value seems to be set, but only after i first click on the second dropdownlist then i get the right "name" in the list. Anything i'm doing wrong?
<script>
function contractorChanged() {
$.ajax({
type:
"POST"
,
url:
'@Url.Action("GetContactPersons", "Permission")'
,
data: {
id: $(
"#ContractorId"
).val()
},
cache:
false
,
success: function (data) {
$(
"#ContractorPersonId"
).data(
"kendoDropDownList"
).setDataSource(data);
$(
"#ContractorPersonId"
).data(
"kendoDropDownList"
).value(
'@Model.ContractorPersonId'
);
}
});
}
</script>
@(Html.Kendo().DropDownListFor(model => model.ContractorId)
.HtmlAttributes(
new
{ style =
"width:100%; margin-bottom: 8px;"
})
.OptionLabel(
"Välj företag"
)
.DataTextField(
"Name"
)
.DataValueField(
"Id"
)
.Events(e => e.DataBound(
"contractorChanged"
))
.DataSource(source =>
{
source.Read(read => { read.Action(
"GetConstructors"
,
"Permission"
); });
}))
@(Html.Kendo().DropDownListFor(model => model.ContractorPersonId)
.HtmlAttributes(
new
{ style =
"width:100%"
})
.OptionLabel(
"Välj kontaktperson"
)
.DataTextField(
"FullName"
)
.DataValueField(
"Id"
)
.Enable(
false
)
.AutoBind(
false
)
.CascadeFrom(
"ContractorId"
)
)