Hello Telerik,
I'm having some trouble implementing the scenario I need (not a very complex one, indeed), which is the following.
I use the Policy class as Model, which contains a Contractor property, marked with [Required] attribute. The Contractor class contains the "Id" and "Name" properties. On the View, I need to add a DropDownList which loads and displays the available contractors list (only when the user opens it), stores the selected contractor, validates it (it is mandatory), and keeps it persistently stored also when refreshing the page (e.g. after a callback which notifies failed validations on the page).
On the View I added:
<td>
@(Html.Kendo ( ).DropDownListFor ( model => model.Contractor )
.DataTextField (
"Name"
)
.DataValueField (
"Id"
)
.HtmlAttributes (
new
{ style =
"width: 200px;"
, id =
"contractorComboBox"
} )
.AutoBind(
false
)
.DataSource ( source =>
{
source.Read ( read => read.Action (
"searchcustomers"
,
"customer"
) ).ServerFiltering (
true
);
} )
)
</td>
<td>
@Html.ValidationMessageFor(model => model.Contractor,
""
,
new
{ @
class
=
"text-danger"
})
</td>
The SearchCustomers method on the Customer controller simply retrieves a list of available Customer instances.
With this code, the list is correctly retrieved and bound, and also the validation appears. Unfortunately, when some data is selected in the dropdown, it is not posted on the Controller (the Contractor property is null). Furthermore, when the page is refreshed, also the error message "The value '3' is invalid" appears in the validation field.
Could you please give me a hand to understand what I am doing wrong?
Thank you