0

I'am developing MVC 4 app with Razor engine using some Kendo UI elements. The Kendo's ComboBox has "Template" property to set HTML template for rows in ComboBox. Within this template I have IMG element that using Url.Action in it's SRC. However I don't know how to pass value to parameter ID. In the following code I hard-coded value to 61 but I need "data.KodFazeBiljkeId" just like written in the ALT attribute.

Here is my VIEW with Kendo's ComboBox:

@(Html.Kendo().ComboBoxFor(model => model.MaticniKodFazeBiljke1Id)
    .Name("MaticniKodFazeBiljke1Id")
    .Placeholder("Odaberi razvojnu fazu biljke...")
    .DataTextField("OpisDvocifrenogKoda")
    .DataValueField("KodFazeBiljkeId")
    .HtmlAttributes(new { style = "width:500px" })
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("getKodoviFazeBiljke_byRazvojnaFazaBD", "KodFazeBiljke")
                .Data("filterRazvojnaFazaBD");
        })
        .ServerFiltering(true);
    })
    .Enable(false)
    .AutoBind(false)
    .CascadeFrom("RazvojnaFazaBDId")
    .Height(300)
    .Template("<img src=\"" + Url.Action("GetPhoto", "KodFazeBiljke", new { id = 61, thumb = true }) + "\" alt=\"${data.KodFazeBiljkeId}\" />" +
            "<dl>" +
                "<dd>${ data.OpisDvocifrenogKoda }</dd>" +
            "</dl>")
)
4

1 回答 1

0

你的模板应该是这样的

<script id="Template" type="text/x-kendo-template">
<img src='/KodFazeBiljke/GetPhoto?id =${data.KodFazeBiljkeId}&thumb = true' alt='${data.KodFazeBiljkeId}" />
<dl>
    <dd>${ data.OpisDvocifrenogKoda }</dd>
</dl>
</script>

你可以像这样设置模板

.Height(300)
.Template('#Template')

Template是模板脚本 ID

于 2013-10-20T13:57:42.137 回答