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

Problem with server binding to controler arguments

0 Answers 24 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Martin
Top achievements
Rank 1
Martin asked on 23 Mar 2012, 08:16 AM
Hi,

If I use TreeView in EditorTemplate then after post back the checked values is not correctly bind to controller arguments.

Index.cshtml
@Html.EditorFor(model => model.Data, "DataTree")

DataTree.cshtml
@(Html.Telerik().TreeView()
            .Name(ViewData.TemplateInfo.HtmlFieldPrefix + ".TreeList")
            .ShowCheckBox(true)

After post back I can see that in Request.Form is keys like Data_DataTree_checked[].Value etc. But Default binder search for Data.DataTree..... than i have binded checked items  but not theirs Text and Value property but only Checked property. Its because TreeView renders checked inputs on server with correct names.

Main problem is that in HTML id attribute cannot contain dot character "." and is replaced with underscore character and in treeview JS in method nodeCheck is used construction this.element.id for getting part of name attribute for generated hidden inputs. After that the same string is used for getting index value of checked box, but the search is against name attribute witch contains dot character as separator.

I solved this when on server I add my own attribute data-name with correct name attribute and then in JS I overwrite nodeCheck this.element.id with
$(this.element).attr('data-name') 

Is this correct?

Regards.



Tags
TreeView
Asked by
Martin
Top achievements
Rank 1
Share this question
or