could not be set to a 'System.Decimal' value. You must set this property to a non-null value of type 'System.Double'

asp.net-mvc, c#, sql-server

Solution

I think it might be because of null value conversion attempt to be stored in double.

Change your `double` to

double?

For explanation, please see the link below: http://msdn.microsoft.com/en-us/library/2cf62fcy.aspx

Thanks!

Problem

Hi i am using mvc example to get data from a database. Here i got an error Exception Details: System.InvalidOperationException: The 'number' property on 'Employee' could not be set to a 'System.Decimal' value. You must set this property to a non-null value of type 'System.Double'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Please see my code here, i got above error. ``` public ActionResult Details(int id) { EmployeeContext empcon = new EmployeeContext(); Employee employ = empcon.employees.Single(emp => emp.empid == id); return View(employ); } ``` Routiconfig ``` public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); RouteTable.Routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "emp", action = "Details", id = UrlParameter.Optional } ); } ```

Original source