unable to cast object of type system.string to system.decimal

SathyanarayananAV 1 Reputation point
2022-09-26T06:42:40.05+00:00

I am new to asp.net MVC core programming. I have got with previous experience in asp.net web pages. Can somebody help me regarding this.

This is the EmployeeController code:-
using BusinessLayer.Models;
using Microsoft.AspNetCore.Mvc;

namespace ERP.Controllers
{
public class EmployeeController : Controller
{

    private readonly EmployeeDBContext _db;  

    public EmployeeController(EmployeeDBContext db)  
    {  
        this._db = db;  
    }  

    public IActionResult Index()  
    {  
        List<Employee> emps = _db.Employees.ToList();  
        return View(emps);  
    }  
}  

}
Employee Model:-

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BusinessLayer.Models
{
[Table("Employees")]
public class Employee
{
[Key]
public int Eno { get; set; }
public string Ename { get; set; }

    public decimal Salary {get; set; }  

    public string Job { get; set; }  

    public string Dname { get; set; }  



}  

}

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,249 questions
{count} votes