This is a migrated thread and some comments may be shown as answers.

How could i get selected value from dropdownlist in kendo ui grid in mvc

2 Answers 876 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Varma
Top achievements
Rank 1
Varma asked on 14 Jul 2012, 02:42 PM
I am working on Kendo UI with asp.net mvc razor. I am trying to bind database table data with kendo grid that supports CRUD operations. Here i need to populate a dropdownlist for one of my table field. I have used the following code


**View:**


    @model IEnumerable<MvcApplication1.PriceOption>    
    @(Html.Kendo().Grid(Model)
            .Name("Grid")
            .Columns(columns =>
            {
                //columns.Bound(p => p.ProductTitle).ClientTemplate("<input type='checkbox' disabled='disabled'name='Discontinued' <#= Discontinued? checked='checked' : '' #> />");
                columns.Bound(p => p.ProductTitle).EditorTemplateName("OptionalEmail");
                columns.Bound(p => p.OptionTitle);
                columns.Bound(p => p.Price);
                columns.Bound(p => p.Frequency);
                columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
        
        
        
            })
            .ToolBar(toolbar => toolbar.Create())
                .Editable(editable => editable.Mode(Kendo.Mvc.UI.GridEditMode.InLine))
            .Pageable()
            .Sortable()
            .Scrollable()
            .DataSource(dataSource => dataSource
                .Ajax()
                .Events(events => events.Error("error_handler"))
                .Model(model => model.Id(p => p.ProductID))
                .Create(create => create.Action("CreateOption", "ZiceAdmin"))
                .Read(read => read.Action("Read", "ZiceAdmin"))
                .Update(update => update.Action("UpdateOption", "ZiceAdmin"))
                .Destroy(update => update.Action("DeleteOption", "ZiceAdmin"))
            )
        )


**OptionalEmail.cshtml**


    @model string
    @(Html.Kendo().DropDownList()
        .Name("ProductTitle")
        .Value(Model)
        .SelectedIndex(0)
        .BindTo(new SelectList(ViewBag.ProductTitle))
     )


Here i need to store the selected item from the dropdownlist. But it always shows null. How could i get the selected value from dropdownlist.

2 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 18 Jul 2012, 11:26 AM
Hi Varma,

Could you please modify the Editor template DropDownList configuration similar to the following:

@(Html.Kendo().DropDownList()
        .Name("ProductTitle")
        .DataValueField("Title"
        .DataTextField("Title")
        .BindTo(ViewBag.ProductTitle) // an collection of entries which have a Title property
)

Also an example of similar custom editor could be found in the demo samples (under Grid->Editing custom editor) available within  the KendoUI for ASP.NET MVC distribution package.Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gibi
Top achievements
Rank 2
answered on 17 Sep 2012, 09:34 PM
The demo code is not what demo is. Check it out.
Tags
Grid
Asked by
Varma
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Gibi
Top achievements
Rank 2
Share this question
or