I have a Kendo Dropdown that I'm loading using WebApi. User selects an option from the dropdown and hits search button that does a postback action. The selection is visible in the controller on the POST action but when the page reloads after postback, the dropdown has lost its selection and is blank now.
How can I have the value selected in dropdown on page reload ?
<div class="row">
<div class="col-md-3">
@(Html.Kendo()
.DropDownListFor(m => m.SelectedId)
.DataTextField("Name")
.DataValueField("Id")
.HtmlAttributes(new { style = "width:100%" })
.Value("TEST")
.AutoBind(false)
.Filter("contains")
.MinLength(3)
.DataSource(source =>
{
source.Read(read =>
{
read.Url("/api/GetNames/" + @Model.PersonnelId);
})
.ServerFiltering(true);
})
)
</div>
<div>
<button name="Search" value="true" type="submit" class="btn btn-secondary">Search</button>
</div>
</div>
I was wondering if on postback, I can use the SelectedId to find the "Name" and show it selected by assigning in .Value() property of dropdown after postback. To test this, I first hardcoded value "TEST" in the dropdown, but I don't see it selected anytime (on first time load or on reload).
Initially I thought it is because of Autobind(true), so I've set it to false so that dropdown loads only after user starts typing. That still hasn't helped with retaining the selection when value is loaded from controller.