C# 将产品发布到服务器时是否调用ASP.NET MVC 2.0未使用的模型属性?
我有我的自动生成的linq到sql类,我使用部分分类(而不是使用继承)扩展这个类,并且我有我在后面放入的属性,这些属性不是数据库模型的一部分,也不应该是。这些是类似于“最终价格”和“显示最终价格”的东西-在数据库中,只有零售价格和批发商价格,因此最终价格等更像是数据库字段的扩展 当我提交表格时,没有填写任何内容,“最终价格”会被称为(财产的“获取”),即使我从未要求,即使它不需要。这发生在验证之前,所以我甚至没有得到我会得到的验证错误 我试过在FinalPrice和FinalPriceDisplay属性上使用和-不!为什么会发生这种情况?我怎样才能阻止它发生?modelstate是否只是尝试验证所有内容,因此无论发生什么情况,它都会调用每个项 对于那些感兴趣的人,这里是所有的代码 部分公共类产品 '继承tProduct 专用常量佣金乘数,十进制=CDec(1.18) 私人最终价格为十进制? Private\u将最终价格显示为字符串 Private\u将正常价格显示为字符串C# 将产品发布到服务器时是否调用ASP.NET MVC 2.0未使用的模型属性?,c#,asp.net,asp.net-mvc,vb.net,asp.net-mvc-2,C#,Asp.net,Asp.net Mvc,Vb.net,Asp.net Mvc 2,我有我的自动生成的linq到sql类,我使用部分分类(而不是使用继承)扩展这个类,并且我有我在后面放入的属性,这些属性不是数据库模型的一部分,也不应该是。这些是类似于“最终价格”和“显示最终价格”的东西-在数据库中,只有零售价格和批发商价格,因此最终价格等更像是数据库字段的扩展 当我提交表格时,没有填写任何内容,“最终价格”会被称为(财产的“获取”),即使我从未要求,即使它不需要。这发生在验证之前,所以我甚至没有得到我会得到的验证错误 我试过在FinalPrice和FinalPriceDispl
Public Property CategoryComplete As Short
<ScaffoldColumn(False)>
Public ReadOnly Property FinalPrice As Decimal
Get
'If RetailPrice IsNot Nothing OrElse WholesalePrice IsNot Nothing Then
If _FinalPrice Is Nothing Then
If RetailPrice IsNot Nothing Then
_FinalPrice = RetailPrice
Else
_FinalPrice = WholesalePrice * CommissionMultiplier ' TODO: this should be rounded to the nearest 5th cent so prices don't look weird.
End If
Dim NormalPart = Decimal.Floor(_FinalPrice.Value)
Dim DecimalPart = _FinalPrice.Value - NormalPart
If DecimalPart = 0 OrElse DecimalPart = 0.5 Then
Return _FinalPrice
ElseIf DecimalPart > 0 AndAlso DecimalPart < 0.5 Then
DecimalPart = 0.5 ' always rounded up to the nearest 50 cents.
ElseIf DecimalPart > 0.5 AndAlso DecimalPart < 1 Then
' Only in this case round down if its about to be rounded up to a valeu like 20, 30 or 50 etc as we want most prices to end in 9.
If NormalPart.ToString.LastChr.ToInt = 9 Then
DecimalPart = 0.5
Else
DecimalPart = 1
End If
End If
_FinalPrice = NormalPart + DecimalPart
End If
Return _FinalPrice
'End If
End Get
End Property
<ScaffoldColumn(False)>
Public ReadOnly Property DisplayFinalPrice As String
Get
If _DisplayFinalPrice.IsNullOrEmpty Then
_DisplayFinalPrice = FormatCurrency(FinalPrice, 2, TriState.True)
End If
Return _DisplayFinalPrice
End Get
End Property
Public ReadOnly Property DisplayNormalPrice As String
Get
If _DisplayNormalPrice.IsNullOrEmpty Then
_DisplayNormalPrice = FormatCurrency(NormalPrice, 2, TriState.True)
End If
Return _DisplayNormalPrice
End Get
End Property
Public ReadOnly Property DivID As String
Get
Return "pdiv" & ProductID
End Get
End Property
End Class
我可以通过在代码中包装注释掉的if语句来解决这个问题,但首先不应该调用它,这就是我遇到的问题。看起来您遇到了这个问题(可能是同一个问题?):
谢谢,你说得对,问题完全一样。赞成票:)
Dim NormalPart = Decimal.Floor(_FinalPrice.Value)