Hello,
I am trying my hands on ASP.NET Core MVC. I have developed 1 view, controller and model. When I try to show the data on the homepage using VieModel, it gives me error "SqlException: Invalid object name 'PremiumEarned'."
My table names are MIS_PRM_EARNED_AS_ON_DATE and MIS_CLM_PAID_AS_ON_DATE
My model code is as below.
public class MIS_PRM_EARNED_AS_ON_DATE
{
[Key]
public decimal PRM_AMOUNT { get; set; }
}
public class MIS_CLM_PAID_AS_ON_DATE
{
[Key]
public decimal CLM_AMOUNT { get; set; }
}
My ViewModel class is as below.
public class HomePageVM
{
public List<MIS_PRM_EARNED_AS_ON_DATE> PremEarned { get; set; }
public List<MIS_CLM_PAID_AS_ON_DATE> ClmPaid { get; set; }
}
My Controller Code is as below.
private readonly ApplicationDbContext _db;
public HomeController(ApplicationDbContext db)
{
_db = db;
}
public async Task<IActionResult> Index()
{
HomePageVM VM = new HomePageVM();
VM.PremEarned = await _db.PremiumEarned.ToListAsync();
VM.ClmPaid = await _db.ClaimPaid.ToListAsync();
return View(VM);
}
In the view, I am using the below code to show the data.
@Model.PremEarned
Where am I going wrong? Why is it saying table does not exist?
Thanks.
Regards
Shailesh