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

3 posts, 0 answers
  1. Varma
    Varma avatar
    1 posts
    Member since:
    Sep 2010

    Posted 14 Jul 2012 Link to this post

    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. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 18 Jul 2012 Link to this post

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Gibi
    Gibi avatar
    3 posts
    Member since:
    Oct 2008

    Posted 17 Sep 2012 Link to this post

    The demo code is not what demo is. Check it out.
Back to Top