ASP.NET MVC4编码错误

时间:2016-01-24 21:15:03

标签: c# html asp.net-mvc-4

     @{
        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?)

1 个答案:

答案 0 :(得分:2)

C#是一种区分大小写的语言。您需要Value中的Capital V。并且ToString需要是驼峰式的。这将允许代码编译。

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