Reputation: 21
@{
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>
when i am running this code in visual studio 2012 it gives me an error error CS0037: Cannot convert null to 'decimal' because it is a non-nullable value type
>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?)
Upvotes: 2
Views: 137
Reputation: 33938
C# is a case-sensitive language. You need Capital V in Value
. And ToString
needs to be camel case. This will allow the code to compile.
@auction.CurrentPrice.Value.ToString("c")
Upvotes: 2