2012-07-29 118 views
5

我想讓我的頭繞過淘汰賽mvc框架。我在看的sample of a shopping cart並試圖找出:如何計算淘汰賽MVC購物車樣品的總購物車價值

  1. 如何計算總成本
  2. 何處添加客戶端業務規則(如折扣和優惠券)

要計算小計的代碼讀數

@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)     
    } 
} 

當我tr y從那裏得到總數,我通常會在運行時結束編譯器異常或NullReferenceException。例如

@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;} 
    } 
} 

給我

編譯器錯誤信息:CS1501:爲方法 '寫入' 沒有重載採用0 參數

好像我做錯了。有人會指出我正確的方向嗎?

+0

它指出哪一行出現此錯誤?此外,這是您首次嘗試使用KO還是僅使用KO MVC框架? – 2013-09-15 00:15:22

回答

0

您是否嘗試從每行的開頭刪除@符號?我敢肯定,一旦你打開一個剃鬚刀代碼塊,你不需要在每一行都預先加上@。另外,不確定爲什麼'雙重總計'行被封裝在{}中?

@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; 
}