javascript - Inexplicable MVC model data alteration -
i have model object contains list of objects have 3 numeric fields , 1 string field, similar following:
public class datamodel { public list<dataitemmodel> dataitems { get; set; } } public class datamodel { public string comment { get; set; } public decimal value { get; set; } public int id { get; set; } public int integervalue { get; set; } } the view has table allows user set each item's value , comment fields (id generated data layer , integervalue derived value). user can add , delete items collection via ajax, using jquery post() method, webpage being partially updated using html().
the issue i'm seeing if have list of comment/value pairs so:
item 1, 1.00 item 2, 2.00 item 3, 3.00 item 4, 4.00 item 5, 5.00 and delete third item via webpage, controller correctly changes data to:
item 1, 1.00 item 2, 2.00 item 4, 4.00 item 5, 5.00 and returns new html using partialview(). when webpage updated, model somehow transformed be:
item 1, 1.00 item 2, 2.00 item 3, 3.00 item 4, 4.00 i have confirmed using vs2013's debugger , firefox's network packet analyser thing, @ loss how or why happens. don't think it's caching issue, jquery docs post() never caches definition. guess has witht call partialview()?
edit: (partial) view in question table inside html form, placed inside div using jquery's html() method.
update: i've done more debugging, , have managed eliminate call partialview() being @ fault; it's returning correctly formed partialviewresult.
it seems can fix whole shebang calling modelstate.clear() @ beginning of controller method. have no idea why works, know adding 1 line has fixed issue.
Comments
Post a Comment