我正试图围绕淘汰mvc框架。我正在查看sample of a shopping cart并试图找出:
计算代码的小计读数
@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)
}
}
当我尝试从那里获得总数时,我通常在运行时最终会遇到编译器异常或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:方法“Write”的过载不为0 参数
好像我做错了。有人会指出我正确的方向吗?
答案 0 :(得分:0)
您是否尝试从每行的开头删除@符号?我敢肯定,一旦你打开一个剃刀代码块,你就不需要在每个行前面加上@。另外,不确定为什么'double total'行包含在{}?
中@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;
}