I have a grid that uses an EditorTemplate for a foreign key of values:
c.ForeignKey(r => r.drugID, (IEnumerable<Model.Models.Drug>)ViewData["SQDrugs"],
"drugID", "drugName").EditorTemplateName("SQDrugs").Title("Drug").Width(150).HeaderHtmlAttributes(new { title = "Drug" });
The Grid's edit mode is Popup:
.Editable(e =>
{
e.Mode(GridEditMode.PopUp);
e.Enabled(canEdit);
})
However, when I went to add/edit a record this drugID column was displayed as a checkbox with the numeric PK value displayed of the list of drugs. It was actually quite easy to fix after spending an hour of research.
I simply added the following UIHint to the drugID property of the model:
[UIHint("GridForeignKey")]
public int drugID { get; set; }
FYI, the editor's code is more or less like this:
@(Html.Kendo().DropDownListFor(model => model)
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetSQDrugs", "PHMedications");
});
})
.DataTextField("drugName")
.DataValueField("drugID")
.Name("drugID")
.Events(e => e.Change("onChange"))
.OptionLabel("- Please select -")
.HtmlAttributes(new { data_value_primitive = true })
)
No comments:
Post a Comment