5 Answers, 1 is accepted
I am afraid that the provided information is not sufficient, in order to determine what is the reason for the experienced issue. Could you share your implementation, so we could investigate the problem further?
Regards,
Nencho
Telerik by Progress
Model
public
class
WeightUnit
{
public
byte
ID {
get
;
set
; }
public
string
Code {
get
;
set
; }
public
string
Description {
get
;
set
; }
}
Controller action
public
ActionResult WeightUnits_Read([DataSourceRequest]DataSourceRequest request)
{
IEnumerable<ServiceLayer.ServiceModel.WeightUnit> results = svc.ListWeightUnits();
return
Json(results.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
Code section in View
<
div
id
=
"weights"
class
=
"panel-group"
style
=
"padding-left:5px;"
>
@Html.Label("Unit", new { style = "width:80px;" })
@(Html.Kendo().DropDownList()
.Name("WghtUnit_ID")
.OptionLabel(Labels.PleaseSelect)
.DataSource(source =>
{
source.Custom()
.ServerFiltering(false)
.Type("aspnetmvc-ajax")
.Transport(transport =>
{
transport.Read("WeightUnits_Read", "Utility");
})
.Schema(schema =>
{
schema.Data("Data")
.Total("Total");
});
;
})
.DataTextField("Description")
.ValueTemplate("#: data.Code # - #: data.Description #")
.DataValueField("ID"))
</
div
>
Problem
In a basic view (not in an editor pop template called from a grid) the DDL ValueTemplate line renders the selected value perfect
e.g.
'KGS - Kilograms'
However when used inside an editor template i.e. popup editor to add a new record, the selected value is shown as :
Undefined - undefined.
What needs to be done differently when using ValueTemplates in a DDL configured in an editor popup ?
I am afraid that we are unable to reproduce the issue on our side. Would you please modify the attached project so that it represents your implementation where the problem appears and send it back to us? Thus, we would be able to investigate locally and help you more efficiently. Adding a reference to the Kendo.Mvc.dll assembly should be sufficient for running the project.
Regards,
Peter Milchev
Telerik by Progress
Hello Peter,
In modifying the project you kindly prepared, I have solved the problem! Apologies, but I did not acurately describve the problem, which was that the editor template was being called from a nested grid. To fix I simply needed to alter the ValueTemplate as follows:
.ValueTemplate("\\#: data.Code \\# - \\#: data.Description \\#")
note the backslashes.
Sorry, I should have realised this sooner - case closed.
Thanks,
Mike James
Thank you for sharing the solution with the community.
Indeed the nested templates should be escaped according to the Kendo Templates Overview article. The deeper the nesting the more double backslashes you should use for escaping.
- If your template includes a literal # character, which is not part of a binding expression and is not a script code marker, then you must escape that character or it causes a template compilation error. For example, this can happen if a # is used inside a hyperlink URL or a CSS color value. Literal # in JavaScript strings are escaped via \\\\#, while literal # in external HTML script templates are escaped via \\#.
- If your template includes a # character, which is part of a binding expression of a nested template, then this character must be escaped as well. In this way the character is ignored by the outer template, but is handled correctly by the inner template.
Regards,
Peter Milchev
Telerik by Progress