I am trying to get my head around knockout mvc framework. I am looking at the sample of a shopping cart and trying to figure out:
- How to calculate total cost
- Where to add client side business rules (such as discounts and vouchers)
To calculate subtotal the code reads
@using (lines.If(m => m.ProductId != -1))
{
using (var product = lines.With(m => ko.Model.DataBase[m.CategoryId].Products[m.ProductId]))
{
@product.Html.Span(m => "\\$" + m.Price)
}
}
When I try to get the total from there I usually end up with a compiler exception or NullReferenceException in run time. For example
@using (lines.If(m => m.ProductId != -1))
{
using (var product = lines.With(m => ko.Model.Categories[m.CategoryId].Products[m.ProductId]))
{
@product.Html.Span(m => "\\$" + (lines.Model.Quantity * m.Price))
@{double total = lines.Model.Quantity * m.Price;}
}
}
Gives me
Compiler Error Message: CS1501: No overload for method 'Write' takes 0 arguments
Seems like I am doing it wrong. Would anyone point me in a right direction?