@{
var auction = new MvcAuction.Models.auction()
{
Title = "Example Auction",
Description = " This is an example Auction ",
Starttime = DateTime.Now,
EndTime = DateTime.Now.AddDays(7),
StartPrice = 1.00m,
CurrentPrice=null;`
};
}
<div class ="Auction" />
<h3>@auction.Title</h3>
<div class="Details"></div>
<p> StartTime : @auction.Starttime.ToString("g")</p>
<p> EndTime:@auction.EndTime.ToString("g")</p>
<p>StartingPrice : @auction.StartPrice.ToString("c")</p>
<p> CurrentPrice:
@if (auction.CurrentPrice == null)
{
@: [No Bids]
}
else
{
<span>@auction.CurrentPrice.value.tostring("c")</span>
}
</p>
当我在visual studio 2012中运行此代码时,它给了我一个错误 错误CS0037:无法将null转换为&#39;十进制&#39;因为它是一个不可为空的值类型
>error CS1061: 'decimal' does not contain a definition for 'value' and no extension method 'value' accepting a first argument of type 'decimal' could be found (are you missing a using directive or an assembly reference?)
答案 0 :(得分:2)
C#是一种区分大小写的语言。您需要Value
中的Capital V。并且ToString
需要是驼峰式的。这将允许代码编译。
@auction.CurrentPrice.Value.ToString("c")