PDA

View Full Version : writeAllFields - ID Never Makes It To My MVC Controller



rosspaul@utah.gov
27 Jul 2012, 1:55 PM
I have a grid that a user may dclick to edit a row which then pops a edit form (modal). Upon save it does an update user.

updateUser: function (button) {
var win = button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues(),
store = this.getUsersStore();

record.set(values);
win.close();
}

Values above has data as shown below INCLUDING THE ID.

+ Id "69290" String
+ FirstName "Ross" String
+ LastName "Paul" String
+ LoginId "rossspaul" String
+ EntityType "4" String
+ EntityName "Paul, Ross S " String
EmailAddress "" String
+ LastModifiedBy "[object Object]" String
+ DateLastModified "/Date(1341500122100)/" String
+ MiddleName "S" String
+ ObscureName "Ross P." String
DateOfBirth "" String
DateOfDeath "" String
+ Gender "0" String

The problem I'm experiencing is when the json call is made to my MVC controller the ID IS MISSING.

[HttpPost]
public ActionResult Update(User user)
{

user.Id is 0 every time. Any help would be great.

scottmartin
27 Jul 2012, 5:18 PM
Can you clarify when you lose the id?

-Present in header when sent?
-Present at server to update data.
-Lost/present on return JSON back from server?

Scott.

rosspaul@utah.gov
30 Jul 2012, 9:09 AM
Scott, thanks for your reply. After more debugging I think I know the issue but not sure on the resolution. Here's what being posted in JSON.

jsonData: Object
DateLastModified: "/Date(1341500122100)/"
DateOfBirth: ""
DateOfDeath: ""
EmailAddress: ""
EntityName: "Paul, Ross S "
EntityType: "4"
FirstName: "Ross"
Gender: "0"
Id: "69290"
LastModifiedBy: "[object Object]"
LastName: "Paul"
LoginId: "rossspaul"
MiddleName: "S"
ObscureName: "Ross P."
id: undefined

You can see there are two id values (Id and id). Mine that is bound to my user object and grid is the Id with a capital "I". There is another that appears to be generated by extJS and it's undefined. What happens is when it hits my MVC controller in the update user method it's binding to my C# object. Because the default translator is not case sensitive it appears to be taking the later (id) which is undefined thus resulting in a zero in my controller. This is preventing me from doing my update by Id to the dbase.

Q - Is extJS reserving "id" or adding that in for some reason?
Q - If so, how do I get around this because all of our business objects use Id for sql server auto ids's etc?

scottmartin
30 Jul 2012, 9:25 AM
If you set idProperty 'Id', it should eliminate the auto 'id' field.

Scott.

rosspaul@utah.gov
30 Jul 2012, 9:36 AM
I've done that in my store but still does not fix the issue. Is there somewhere else I need to do that?

Ext.define('SW.store.Users', {
extend: 'Ext.data.Store',
model: 'SW.model.User',
idProperty: 'Id',
autoLoad: true,
autoSync: true,
pageSize: 20,
proxy: {
type: 'ajax',
limitParam: 'size',
startParam: undefined,
api: {
create: '/user/add',
read: '/user/list',
update: '/user/update',
destroy: '/user/delete'
},
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
},
writer: {
type: 'json',
writeAllFields: true
}
}
});

scottmartin
30 Jul 2012, 10:09 AM
hmm.. try idProperty 'id' instead of 'Id'

If this does not work, report back and I will have a closer look.

Scott.

rosspaul@utah.gov
30 Jul 2012, 10:42 AM
No dice. I've attached a couple images so you can see what's going on.

rosspaul@utah.gov
31 Jul 2012, 3:15 PM
Did we ever get this figured out?

mankz
31 Jul 2012, 8:15 PM
This is the bug report for this bug. http://www.sencha.com/forum/showthread.php?203635-4.1.0-id-field-leak&p=863715

rosspaul@utah.gov
1 Aug 2012, 7:36 AM
Any quick fix you've seen in the interim?

rosspaul@utah.gov
1 Aug 2012, 8:06 AM
Adding the idProperty to my model seems to fix my issue until 4.2 addresses this globally.

Ext.define('SW.model.User', {
extend: 'Ext.data.Model',
idProperty: 'Id',
fields: ['Id', 'EntityType', 'EntityName', 'EmailAddress', 'LastModifiedBy', 'DateLastModified', 'FirstName', 'MiddleName', 'LastName', 'ObscureName', 'DateOfBirth', 'DateOfDeath', 'Gender', 'LoginId']
});