KnockoutMVC 2.10,MVC 4.0,C#5。
使用主站点上的一个示例(子模型中的计算字段)。我遇到了问题,想知道是否有人可以提供帮助。在下面的代码中,计算出的Message字段根据与Caption和Value关联的两个文本框分别更新。但是,只要我取消注释第二个[Computed]属性,而对View(或任何其他代码)没有其他更改,它就会停止工作。顺便说一下,在同一个项目中,在主模型中我尝试了2个计算字段并且它们工作正常。这是子模型的限制(即只允许一个计算字段)?
由于 罗布
public class InnerComputedSubModel
{
public decimal Caption { get; set; }
public decimal Value { get; set; }
public decimal Caption2 { get; set; }
public decimal Value2 { get; set; }
[Computed]
public decimal Message
{
get { return Caption * Value; }
}
//[Computed]
public decimal Message2
{
get { return Caption2 * Value2 * 20; }
}
}
public class InnerComputedModel
{
public InnerComputedSubModel SubModel { get; set; }
}
答案 0 :(得分:2)
KnockoutMVC支持多个Computed
属性,但在decimal
属性中使用Computed
值时会出现一些错误。
一种可能的解决方法是不要在decimal
中使用Computed
,但float
或double
之外不存在与C#{{1}相当的JavaScript } type。
所以下面的代码应该可以正常工作:
decimal