asp.net mvc - What can cause automapping to behave differently in different MVC app with same code? -


i have test app works following classes in 1 app, not in another:

public class valuechange {     public int groupid { get; set; }     public list<itemvaluechange> changes { get; set; } }  public class itemvaluechange {     public int itemid { get; set; }     public string value { get; set; }     public string key { get; set; } } 

my plugin posts js structure matches structure (changes jquery array).

the raw post data (from fiddler2) looks like:

groupid 1000 changes[0][value]    changes[0][key]  changes[0][itemid]  1 

in test app works , maps data sent valuechange object correctly.

    [httppost]     public jsonresult validate(valuechange change)     {           // changes property has required array of objects/properties     } 

in our main application, ported plugin , classes, post data sent looks like:

groupid 3705 changes[0][value]    changes[0][key]  changes[0][itemid]  81866 

and validate method called looks identical:

    [httppost]     public jsonresult validate(valuechange changes)     {          // changes contains null list , no groupid     } 

if break-point method changes non-null object groupid of 0 , no child elements in changes. can see these values available request.form in debugger:

request.form["groupid"] "3705"  string request.form["changes[0][key]"] ""  string request.form["changes[0][itemid]"]  "81866" string request.form["changes[0][value]"]   ""  string 

q. cause automapping not work in different mvc project type of data?

if simplify valuechange (below) starts working , receives groupid values:

public class valuechange {     public int groupid { get; set; } } 

if send js object data without changes property works e.g.

  { groupid: 123 } 

something list called changes causing mapping fail. have tried array , sending single hard-wired entry js (still fails):

  { groupid: 123, changes: [{itemid: 456, value: "v", key: "k"}] 

omg. auto-mapper will ignore properties if property name matches parameter name!!!

it caused having parameter called changes (vs. change in test app) when property of received data called changes.

solution: changed parameter name e.g.

[httppost] public jsonresult validate(valuechange valuechange) { } 

to clarify, problem occurs first-level property of data passed matches parameter name. if nested property tit not attempt match parameter name.

this little detail needs stapled everyone's desk/hand/head.* :)


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -