Hi there,
We've just hit a strange issue. We have a DropDownList called "Title" that displays "Mr", "Mrs", "Ms" etc. However, we sometimes noticed that the Title submitted to the form was "LoanBorrower". This was strange as the only place "LoanBorrower" existed was in the MVC back end of the page with "ViewBag.Title = "LoanBorrower".
It appears that if the ViewBag has an entry with the same name as a Kendo form element, the elements default value is being set as the value in the ViewBag.
I have tried this with ViewBag entries other than Title, and the result is the same.
At the top of my "Borrower.cshtml" page I have the following:
@{
ViewBag.Title = "LoanBorrower";
}
I stripped the DropDownList down to the bare minimum and still had the problem:
@Html.Kendo().DropDownListFor(m => m.Title)
The control rendered as the following. Note the value is set to "LoanBorrower" which is the value in ViewBag.Title:
<input data-val="true" data-val-length="Title must be between 1 and 20 characters" data-val-length-max="20" data-val-length-min="1" data-val-required="Select a title." id="Title" name="Title" type="text" value="LoanBorrower" />
<script>
kendo.syncReady(function(){jQuery("#Title").kendoDropDownList({});});
</script>
I then changed the Kendo control to a Kendo TextBox and had the same problem:
@Html.Kendo().TextBoxFor(m => m.Title)
The control rendered as the following. Again, the value is set to "LoanBorrower":
<input data-val="true" data-val-length="Title must be between 1 and 20 characters" data-val-length-max="20" data-val-length-min="1" data-val-required="Select a title." id="Title" name="Title" value="LoanBorrower" />
<script>
kendo.syncReady(function(){jQuery("#Title").kendoTextBox({});});
</script>
I then changed the control to a standard HTML Textbox and no longer had the issue.
@Html.TextBoxFor(m => m.Title)
The control rendered as the following. Note that this time, the value is an empty string which is correct.
<input data-val="true" data-val-length="Title must be between 1 and 20 characters" data-val-length-max="20" data-val-length-min="1" data-val-required="Select a title." id="Title" name="Title" type="text" value="" />