0

In the model class, I am trying to display a currency format for the "Price" field, however the code I am using is not producing the desired result, and I have no idea why it is not working. I do not want to hard code the $ on every page, that would be a hassle. Here is the code I have in the model.

 public partial class Item
{
    public int ItemId { get; set; }
    public string ItemDescription { get; set; }
    public Nullable<int> Quantity { get; set; }
    [DisplayName("Price Each")]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:c}")]
    public string Price { get; set; }
    [DisplayName("Due Date")]
    [DisplayFormat(DataFormatString ="{0:d}", ApplyFormatInEditMode = true)]
    public Nullable<System.DateTime> DueDate { get; set; }
    [DisplayName("Date Received")]
    [DisplayFormat(DataFormatString= "{0:d}", ApplyFormatInEditMode = true)]
    public Nullable<System.DateTime> DateReceived { get; set; }
    public string Comments { get; set; }
    [DisplayName("W/O# or Cost Center")]
    public int PurchaseID { get; set; }

    public virtual PurchaseOrder PurchaseOrder { get; set; }
}

Thanks.

Theo
  • 337
  • 3
  • 9
  • 21

1 Answers1

1

Wrong property type.

try:

public decimal Price { get; set; }
Edi G.
  • 2,432
  • 7
  • 24
  • 33
  • I made the change in the model, now I get a Data Entity Core Matching exception. How can I update the database to fix this problem? – Theo Aug 14 '14 at 12:54
  • you have to update your database http://msdn.microsoft.com/en-us/data/jj554735.aspx – Edi G. Aug 14 '14 at 12:59
  • If its a currency, and you don't want to risk mathematical errors, it really should be `decimal`, not `double` –  Aug 14 '14 at 13:00
  • ups.. sorry my bad. (i corrected my answer) http://stackoverflow.com/questions/1165761/decimal-vs-double-which-one-should-i-use-and-when – Edi G. Aug 14 '14 at 13:02