javascript - How to Bind data from Razor to Knockout? -
i using knockout js , mvc.
how bind info @ razor view databind in ko.
i tried doing did not homecoming @ controller.
what trying accomplish here razorview renders rows in step3(view).i want bind these rows knockout can pass info step4(view).
is there improve way??
view:
<tbody data-bind="foreach:apprtable"> @for (int = 0; < userwrinfo.count; i++) { <tr> <td style="text-align: center"> <button type="button" class="btn btn-primary" data-bind="click: $root.submit.bind($data,'@i')">start</button> </td> <td style="text-align: center" data-bind="value: appropriation">@userwrinfo[i].appropriationnumber</td> <td style="text-align: center" data-bind="value: prioritydate">@userwrinfo[i].prioritydate.tostring("mm/dd/yyyy")</td> <td style="text-align: center" data-bind="value: location">@userwrinfo[i].sect @userwrinfo[i].township @userwrinfo[i].range@userwrinfo[i].rangedirectionid</td> <td style="text-align: center" data-bind="value: source">@userwrinfo[i].source</td> @if (userwrinfo.count == userowner.count) { <td style="text-align: center" data-bind="value: owner">@userowner[i].tostring()</td> } else { <td style="text-align: center" data-bind="value: owner"></td> } <td style="text-align: center" data-bind="value: use">@userwrinfo[i].usedescription</td> <td style="text-align: center" data-bind="value: startedby"></td> <td style="text-align: center" data-bind="value: requiredreporting">@userwrinfo[i].isannualreportrequired</td> </tr> } </tbody>
js:
function rowdata(appropriation, prioritydate, location, source, owner, use, startedby, requiredreporting) { var self = this; self.appropriation = ko.observable(appropriation); self.prioritydate = ko.observable(prioritydate); self.location = ko.observable(location); self.source = ko.observable(source); self.owner = ko.observable(owner); self.use = ko.observable(use); self.startedby = ko.observable(startedby); self.requiredreporting = ko.observable(requiredreporting); } function step3viewmodel() { var self = this; self.apprtable = ko.observablearray(); self.apprtable.push(rowdata()); self.submit = function (buttonid) { var apprdata = ko.tojson(self.apprtable()); $.post("/step/step4", { "ad": apprdata }, function (data) { }, 'json'); } } ko.applybindings(new step3viewmodel());
you're creating single element observable array calling rowdata
constructor, you're not passing parameters in.
self.apprtable = ko.observablearray([new rowdata()]);
the function definition requires lot of parameters
function rowdata(appropriation, prioritydate, location, source, owner, use, startedby, requiredreporting)
you're not putting info observables.
javascript asp.net-mvc asp.net-mvc-4 razor knockout.js
No comments:
Post a Comment