javascript - Knockoutjs elegant way of populating the observable properties after posting to server -
i wanted know, elegant way of populating observable properties after posting json server.
my js
var vm = (function() { var commit = function(item) { var model = { name: item.name(), isactive: item.is_active() }; $.post('/to/server/post', model); .done(function(d) { item.id(d.id); }); } }());
in server
public jsonresult post(itemvm model) { var item = new item { name = model.name, isactive = model.isactive }; // saving here , commit database model.id = item.id; return json(model, jsonresultbehavior.denyget); }
while above snippet work. find hard maintain way, there elegant or way of doing this? need returned id
update later on.
btw, i'm using asp.net mvc 5, knockoutjs
any appreciated. thanks
Comments
Post a Comment