In DropDownTreeFor the selected item id isn't binding to the view model property

1 Answer 258 Views
DropDownTree
Valeria
Top achievements
Rank 1
Valeria asked on 13 Jan 2022, 07:01 AM
I have this inside my grid popup editor view:

@model App.UI.Web.Models.SuitViewModel

 

@(Html.Kendo().DropDownTreeFor(x => x.subjectid) .Name("subjectsDDT") .HtmlAttributes(new { style = "width: 500px;" }) .DataSource(ds => ds.Read("ReadDropDownTreeSubjects", "BaseDirectory") ) .Placeholder("Select subject...") .Filter("contains") .DataTextField("name") .DataValueField("id") .ValuePrimitive(true) .ClearButton(false) .Events(ev => ev.Select("watch")) )


The subjectid property of SuitViewModel view model must be equal to the id of the item selected in the dropdowntree but i always receive 0 in my controller. Where is the problem here?

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 17 Jan 2022, 05:19 PM

Hi Valeria,

 

Thank you for writing to us.

This problem is rather strange and to be honest it is somewhat difficult to pinpoint the exact reason of the issue right away. Can you open your Model C# class and check whether the corresponding field has the UIHint data attribute defined? E.g.:
https://demos.telerik.com/aspnet-mvc/grid/editing-custom

        [UIHint("ClientCategory")]
        public CategoryViewModel Category 
Also, can you open the page on Chrome and check the F12 browser inspector console for any script errors interfering?
If these options are not the case, can you open a formal support ticket to send us a runnable version of your app so we can investigate the issue further?

 

Regards,
Eyup
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Valeria
Top achievements
Rank 1
commented on 19 Jan 2022, 07:23 AM

Hi Eyup!

I had this helper inside an editor template for the whole model. Now I'm using an editor template for each property separately and it works fine UNTIL I use that dropdowntree template in a nested grid inside an editor template for another grid. in that case it just gives me an empty textbox and also hides the template for the next property (decimal). How do I fix it? Here's my code and attached screenshots of how editing inside the nested grid works with and without the dropdowntree template.

The view model:
public class SubjectSuitViewModel
    {
        [ScaffoldColumn(false)]
        public int id { get; set; }

        [Required]
        [Display(Name = "Порядковый номер")]
        public short nn { get; set; }

        [Required]
        [Display(Name = "Иск")]
        public int suitid { get; set; }

        [Required]
        [Display(Name = "Предмет")]
        [Range(1, int.MaxValue, ErrorMessage = "Требуется поле {0}")]
        [UIHint("SubjectTree")]
        public int subjectid { get; set; }


        [Display(Name = "Предмет")]
        public string name { get; set; }

        [Required]
        [Display(Name = "Сумма")]
        [UIHint("Currency")]
        public decimal sum { get; set; }

        public SUBJECTSUIT ToEntity(SUBJECTSUIT entity)
        {
            entity.ID = id;
            entity.NN = nn;
            entity.SUITID = suitid;
            entity.SUBJECTID = subjectid;
            entity.SUM = sum;

            return entity;
        }
    }
SubjectTree editor template:

@model int?

@(Html.Kendo().DropDownTreeFor(x => x)
                    .Name("subjectsDDT")
                    .DataSource(ds =>
                        ds.Read("ReadDropDownTreeSubjects", "BaseDirectory")
                    )
                    .Placeholder("Не выбрано")
                    .Filter("contains")
                    .DataTextField("name")
                    .DataValueField("id")
                    .ValuePrimitive(true)
                    .ClearButton(false)
                    .Events(ev => ev.Select("watch"))
                    .ToClientTemplate()
    )

The nested grid inside a popup editor template of another grid:

@(Html.Kendo().Grid<Urist.UI.Web.Models.SubjectSuitViewModel>()
                    .Name("SubjectsGridView")
                    .HtmlAttributes(new { @class = "data-view" })
                    .ToolBar(toolbar => toolbar.Create())
                    .Columns(columns =>
                    {
                        columns.Bound(p => p.nn).Width(50);
                        columns.Bound(p => p.subjectid).ClientTemplate("#=name#").Width(300);
                        columns.Bound(p => p.sum).Format("{0:c}").Width(100).Lockable(false);
                        columns.Command(commands =>
                        {
                            commands.Edit().Text(" ");
                            commands.Destroy().Text(" ");
                        }).Width(300);
                    })
                    .Editable(edit => edit.Mode(GridEditMode.InLine))
                    .Sortable()
                    .Scrollable()
                    .Resizable(r => r.Columns(true))
                    .Events(ev => ev.Edit("onSubjectSuitEdit"))
                    .AutoBind(false)
                    .DataSource(dataSource => dataSource
                                    .Ajax()
                                    .Model(model =>
                                    {
                                        model.Id(p => p.id);
                                        model.Field(p => p.suitid).DefaultValue(Model.id);
                                        model.Field(p => p.nn).Editable(false);
                                        //model.Field(p => p.subjectid).DefaultValue(0);

                                    })
                                    .Create(update => update.Action("CreateForGrid", "SubjectSuitDirectory"))
                                    .Update(update => update.Action("UpdateForGrid", "SubjectSuitDirectory"))
                                    .Destroy(update => update.Action("DestroyForGrid", "SubjectSuitDirectory"))
                                    .Read(read => read.Action("ReadGridViewForSuit", "SubjectSuitDirectory").Data("getSuitId"))
                                    .Events(events =>
                                    {
                                        events.Error("error_handler");
                                    })

                    )
                    .ToClientTemplate()
        )
Eyup
Telerik team
commented on 20 Jan 2022, 09:10 AM

Hi

Before continuing to discuss the technical situation, I would like to clarify something first. It seems that you are using Telerik UI for MVC and Kendo.dll assembly, but I couldn't find active license for this account regarding this product.

Could you first contact your License Representative of your company and ensure that they add your account as a Licensed Developer? Or they can also contact our Sales department for additional inquiries.

Once this is done and an active license is attached to your account, I can then fully test the mentioned behavior and suggest the proper steps to handle the technical issues.


Tags
DropDownTree
Asked by
Valeria
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or