lazerbrain
lazerbrain

Reputation: 161

MVC - Kendo Grid and DropDownList

In EditorTemplates I have defined my dropdownlist as

    @model int?

    @(Html.Kendo().DropDownListFor(m => m)
     .Name("id_sifra")
     .DataValueField("id_sifra")
     .DataTextField("naziv")
     .DataSource(datasource => datasource.Read("Read_SifreDL","Documents").ServerFiltering(true) )
     .HtmlAttributes(new { style = "width:400px" })
     .OptionLabel("---Select---")
    ) 

In the grid I have

columns.Bound(c => c.id_sifra).EditorTemplateName("_SifreEditor").Title("id_sifra");

The Read_SifreDL in DocumentsControllers is

public JsonResult Read_SifreDL()
{
    var sifre = db.Sifre.Select(c => new
    {
        id_sifra = c.id,
        naziv = c.naziv
    }).ToList();

    return Json(sifre, JsonRequestBehavior.AllowGet);
}

The problem is when I do a selection in dropdownlist (in this case it is naziv), and the dropdownlist has closed the valuefield is shown (in this case it is id_sifra). I want naziv to be shown. What is wrong in my approach?

Upvotes: 0

Views: 233

Answers (1)

Mike Debela
Mike Debela

Reputation: 1950

Add nazivin your model and,

columns.Bound(c => c.id_sifra).EditorTemplateName("_SifreEditor").Title("naziv").ClientTemplate("#:naziv#");;

Upvotes: 1

Related Questions