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

sub objects cause not reaching the controller

3 Answers 31 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 27 Jul 2016, 06:27 PM

Currently we have complicated model which has objects.

 

Model:

class Person {
string name{get; set;}
ContactInfo contactInfo{get; set;}
}

class ContactInfo  {
string phoneNumber {get; set;}
string address{get; set;}
}

 

View:

 @(Html.Kendo().Grid(Model.Person).Name("testGrid")
.Columns(columns =>
{
 columns.Bound(x => x.name);
columns.Bound(x => x.ContactInfo.phoneNumber);
....

 

 

in JS Console, with "$("#testGrid").data("kendoGrid").dataSource.data()" I see everything is good at the first load.

 

However, when I edit "phonenumber", the datasource looks like this:

o
-> Person 
     ->Name:"xxx"
     ->ContactInfo
            ->phoneNumber :"xxxx"
             ->address : "xxxxxx"
     ->ContactInfo.phoneNumber: ""

 

we used Jquery.ajax to send the data in js so it has duplicated "ContactInfo.phoneNumber" after stringify, then it never reaches the MVC controller.

 

Questions:
1. How to solve this issue?
2. How to avoid this additional "ContactInfo.phoneNumber" been created?

Thanks!

3 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 29 Jul 2016, 10:49 AM
Hi Robert,

The grid and its datasource are designed to bind to flat data only.

To make this work correctly you may want to add new model that combines all properties inside it. Something like:
class PersonCustomModel {
string name{get; set;}
string phoneNumber {get{return contactInfo.phoneNumber}; set{contactInfo.phoneNumber = value};}
string address{get{return contactInfo.address}; set{contactInfo.address = value};}
 
ContactInfo contactInfo{get; set;}
}

Then you can bind your columns directly to the "phoneNumber" same way as for the "name"

Regards,
Vasil
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Robert
Top achievements
Rank 1
answered on 29 Jul 2016, 04:38 PM

Yes. that's the way we are doing by flatten out the objects. However, we have more than one layer and webapi. This way makes things complicated with a lot of the same mapping. In addition, we have way more fields than this samples which we try to avoid these kind of mapping manually. The client also requests the clean code without doing all those.

May I know if dot property is always empty? if so, we can write a JS method hack to delete all dot properties before sending.

thanks

 

 

0
Vasil
Telerik team
answered on 02 Aug 2016, 02:44 PM
Hello Robert,

You could probably delete the excessive properties. But it is not guaranteed that it will work in wall cases, because it is not meant to be used that way.

Regards,
Vasil
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Robert
Top achievements
Rank 1
Share this question
or