Error in ASP.NET MVC with decimal data type with ComboBox

exceptional

New Member
I'm trying to populate the data for a ComboBox from Entity Framework in an ASP.NET MVC3 page. In Models, I added DataRepository.cs :\[code\] public List<SelectListItem> GetBookPrices() { var BookPrice = (from bookPrice in ddlEntity.tblBook select new SelectListItem { Text = Convert.ToString(bookPrice .Price), Value = http://stackoverflow.com/questions/14045848/Convert.ToString(bookPrice.Price) }).Distinct(); return BookPrice .ToList(); }\[/code\]and DDLProperty.cs:\[code\] public decimal PriceId { get; set; } public List<SelectListItem> PriceValue { get; set; }\[/code\]In my database, I have a Price column as a decimal. I can do the binding correctly for a DropDownList with a varchar datatype without any error, but I could not figure out how to fix the above code to work with it being a decimal. Here is my Controller:\[code\] DataRepository objRepository = new DataRepository(); public ActionResult Price() { DDLProperties objDDL = new DDLProperties(); objDDL.PriceValue = http://stackoverflow.com/questions/14045848/objRepository.GetBookPrices(); return View(objDDL); }\[/code\]Here is the error:\[code\]LINQ to Entities does not recognize the method 'System.String ToString(System.Decimal)' method, and this method cannot be translated into a store expression.\[/code\]It points to the following line: return BookPrice .ToList();I am starting to learn MVC, so any help is much appreciated. Thanks.
 
Back
Top