Hi,
I've got a MVVM kendo dropdownlist for my single page application that gets rendered with a layout.showIn(), all is fine and the dropdownlist is populated from my viewmodels datasource but the autocomplete filtering always passes null back to my controller method.
<script type=
"text/x-kendo-template"
id=
"ddlEventDescrTemplate"
>
<input id=
"ddlEventDescription"
data-role=
"dropdownlist"
data-value-primitive=
"true"
data-filter=
"contains"
data-auto-bind=
"false"
data-bind=
"source: autoCompleteDataForEventDescr, value: apdEventCode"
data-text-field=
"APDEventCode"
data-value-field=
"APDEventCode"
/>
</script>
<script type=
"text/javascript"
>
var
mainViewModel = kendo.observable({
value:
"1"
,
apdEventCode:
"None"
,
selectedEventName:
null
,
items: [
{ id:
"1"
, name:
"Email Addresses"
},
{ id:
"2"
, name:
"User IDs"
}
],
getSelectedEventName:
function
() {
var
selectedEventName =
this
.get(
"selectedEventName"
);
return
kendo.stringify(selectedEventName,
null
, 4);
},
getInputValue:
function
() {
return
this
.get(
"value"
);
},
getEventCodeValue:
function
() {
return
this
.get(
"apdEventCode"
);
},
autoCompleteDataForEventDescr:
new
kendo.data.DataSource({
serverFiltering:
true
,
transport: {
type:
"json"
,
read: {
url:
'@Url.Action("GetEventCodes", "SupportTools")'
}
}
}),
autoCompleteDataForEventName:
new
kendo.data.DataSource({
serverFiltering:
true
,
transport: {
read: {
url:
'@Url.Action("GetEventNames", "SupportTools")'
}
}
})
});
var
router =
new
kendo.Router();
router.route(
"/"
,
function
() {
mainLayout.render(
".panel-body"
);
mainLayout.showIn(
"#ddlInputFormat"
, inputFormatView);
mainLayout.showIn(
"#ddlEventDescription"
, eventDescriptionView);
mainLayout.showIn(
"#ddlEventName"
, eventNameView);
mainLayout.showIn(
"#numericCpdHours"
, cpdHoursView);
kendo.bind($(
"#mainView"
), mainViewModel);
});
router.route(
"/CPDBulkHourUploadStep2"
,
function
() {
mainLayout.destroy();
step2Layout.render(
".panel-body"
);
step2Layout.showIn(
"#cpdStep2View"
, cpdGridView);
});
router.start();
</script>
Controller method:
public
JsonResult GetEventCodes(
string
text)
{
var eventCodes = _repo.GetEventCodes(text);
return
Json(eventCodes, JsonRequestBehavior.AllowGet);
// eventCodes is returned as an IEnumerable<ViewModel>
}
My dropdownlist gets populated fine, but when I try to type in something the autocomplete never gets filtered, upon debugging it turns out that the parameter text is always null it doesn't seem to be passing anything back to the GetEventCodes controller method. Am I missing something here? I've looked at the demos and documentation and it doesn't seem like I'm missing anything.
Side Note: I can't seem to get my templates to render when I move the script/templates to another location e.g. remove it locally, I want to have a separate .cshtml file preferably that will have all my templates and I can call that from my javascript file instead of having it all in one file which creates a lot of clutter.
Thanks.