Click here to Skip to main content
15,664,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

We use Knockout.js and MVC in a Webapp and are having an issue, where the order merchandise total observed is 0 by Knockout.js, as displayed in the GUI. The code seems to be working intermittently, because sometimes we do show the merchandise total in other orders. All orders use the same code and a merchandise total non zero value is always seen in the OrderDetailClientViewModel object within the controller before being passed to the view. The view is coded in Knockout.js and plain javascript.

The "Totals" property shown below is an object (Models.OrderTotalViewModel), which contains the "MerchandiseTotal" field, which is sometimes showing a 0. I'm showing the relevant parts of the two view files below. I don't see the merchandiseTotal value being modified erroneously in the code. Only helpful segments are shown below.

Any suggestions to fix this intermittent behavior would be greatly appreciated!!!

Thank you, Ken

@model Models.OrderEditPageViewModel
var rawViewModel = @(Html.ToJson(Model.OrderDetailClientViewModel()));
var viewModel = ko.mapping.fromJS(rawViewModel,
'HeaderData': {
create: function(options) { = new Date(; = new Date(;
var headerData = ko.mapping.fromJS(;
headerData.errors = new HeaderDataError();
return headerData;

'Totals': {
create: function(options) {
var totals = ko.mapping.fromJS(;
totals.errors = new TotalsError();
totals.isPromoCodeApplied = ko.observable(false);

if ($.trim(totals.PromoCode()) !== "")

return totals;

-- This segment in Edit.cshtml shows where the OrderTotalViewModel.cshtml is called for Totals.
@Html.EditorFor(m => m.Totals)
What I have tried:

I have traced the code and it the value is being supplied to the view.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900