[Required(ErrorMessage = "Drug is required")]
However, the validation message was not appearing.
Originally the editor template for this field was as follows:
@using Kendo.Mvc.UI
@*@model IQueryable<
Model.Models.Drug
>*@
@{
Layout = null;
}
@(Html.Kendo().DropDownList()
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetDrugs", "PHMedications");
});
})
.DataTextField("drugName")
.DataValueField("drugID")
.Name("drugID")
.OptionLabel("- Please select -")
.HtmlAttributes(new { data_value_primitive = true})
)
Telerik Support sent me the following information which resolved my issue:
Please try with the DropDownListFor helper instead of DropDownList with a Name:
@model drugIDType
@(Html.Kendo().DropDownListFor(model => model)
.DataSource(source =>
{
source.Read(read =>
{
read.Action(
"GetDrugs"
,
"PHMedications"
);
});
})
.DataTextField(
"drugName"
)
.DataValueField(
"drugID"
)
.OptionLabel(
"- Please select -"
)
.HtmlAttributes(
new
{ data_value_primitive =
true
})
)
The editor templates are created in the context of the property and will have a prefix the property name. Thus the field that will be used to find the attributes when setting a name will be "PropertyName.PropertyName" and no attributes will be found.
No comments:
Post a Comment