@{
        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转换为“decimal”,因为它是不可为null的值类型
>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?)

最佳答案

C是一种区分大小写的语言。Value中需要大写V。而ToString必须是驼峰病例。这将允许代码编译。

@auction.CurrentPrice.Value.ToString("c")

09-25 15:39