iam using knockout , asp.net mvc , entity framework , know how can go saving info sub view models 1 controller method
in knockout have multiple viewmodels contain different info related each other such when pass controller have pass info pertaining view models, such when save upon clciking save button information saved various "different tables @ simultaneously know how pass 1 view model know how pass 2 models in 1 statement controller "two different methods in controller" current structure
function fullemployeeprofile () var fep = { fep.ei.name = ko.observable(""); fep.ei.id = ko.observable(""); fep.ei.gender = ko.observable(""); fep.ei.address = ko.observable("") ; fep.eh.companyname = ko.observable(); fep.eh.designation = ko.observable(); fep.eh.startdate = ko.observable(); fep.eh.enddate = ko.observable(); } function employeehistory() { var eh = var self = this; eh.companyname = ko.observable(); eh.designation = ko.observable(); eh.startdate = ko.observable(); eh.enddate = ko.observable(); } function employeeeducation() { var ee = this; ee.degree = ko.observable(); ee.yearofpassing = ko.observable(); ee.percentage = ko.observable(); ee.institute = ko.observable() ee.fullemployeedetails = new fullemployeeprofile(); ee.saveemployeedetails = function() { $.when(postsecuredata("/api/employeeprofile/", ko.tojson(ee.fullemployeedetails))) .done(function (empprofile) { if (response.responserequired == false) { document.getelementbyid("save-empdetails-btn").innerhtml = "saving..."; settimeout(function () { document.getelementbyid("save-empdetails-btn").innerhtml = "save" }, 2500); $.msggrowl({ type: 'info', title: 'employee information saved', text: 'employee information details succesfully saved', position: 'bottom-right', lifetime: 3000 }); } }); }; } function employeeinfo() { var ei = this; var ei = this; ei.name = ko.observable(""); ei.id = ko.observable(""); ei.gender = ko.observable(""); ei.address = ko.observable("") ; }
as suggested davidg, encapsulating model approach take. seems you're confusing idea of view models , domain/data models, or @ least concept of view models little confused.
your view model should exactly, literally, sounds like. model contains information need specific view. if need contain multiple views inside main view, need contain multiple view models inside main view model. common practice.
for example:
function employeeprofileandhistory() { var profile = new fullemployeeprofile(); var history = new employeehistory(); } pass api. (code wrong not overly familiar knockout, gist same.)
Comments
Post a Comment