am using Kendo UI with Razor as the frontend and .NET Framework 4.8.1 as the backend.
I have the following code, but it does not initially display "Switzerland".
It is present in the list, but I do not want to select it manually.
I want it to be preselected from the start. Could you please help me?
@model int?
@{
var initialItems = new List<SelectListItem>()
{
new SelectListItem{ Text = "Schweiz", Value = "1" }
};
}
<div class="k-floating-label-container mb-3">
@(Html.Kendo().DropDownListFor(x => x)
.DataTextField("Text")
.DataValueField("Value")
.AutoBind(false)
.BindTo(initialItems)
.Value(Model?.ToString())
.Events(e => e.Open("onDropDownOpen"))
.Deferred()
)
@Html.LabelFor(x => x, new { @class = "k-label k-input-label" })
@Html.ValidationMessageFor(x => x)
</div>
<script>function onDropDownOpen(e) {
var dropdown = $("#Store_DefaultLanguageId").data("kendoDropDownList");
if (dropdown.dataSource.total() === 1) {
dropdown.setDataSource(new kendo.data.DataSource({
transport: {
read: {
url: "/Language/LanguageList",
dataType: "json",
}
},
serverFiltering: true
}));
}
}
</script>