On the post back from a razor page I am expecting the SelectedIndex to set a value for me. but it is always 0.
How do I get it to set the selectedindex?
@(Html.Kendo().DropDownListFor(m => m.Contractor)
.SelectedIndex(Model.Contractor.CompanyId)
.DataTextField("Text")
.DataValueField("Id")
.OptionLabel("Please select")
.BindTo(ViewBag.CompanyId)
)
Also tried:
@(Html.Kendo().DropDownListFor(m => m.Contractor).SelectedIndex(Model.LocationIdSelected)
.DataTextField("Text")
.DataValueField("Id")
.OptionLabel("Please select")
.BindTo(ViewBag.CompanyId)
)
I am not trying to set a default value. Which is what your example does. I need to know what value the user selected. Per my example if the user selects the 5th option "Name 5" then the value returned to the server should not be 0. How do you tell on the server side what option was selected by the user.
Thank you for the additional details. I have updated the initial answer based on the clarifications you shared, but I am still able to observe the value set via the SelectedIndex configuration being sent back to the page handler method, responsible for handling the form submission.