I've looked at numerous examples of this error online. But I don't know enough to apply them. I'm using EF 6.1.2 and Visual Studio 2012. Everything is in one solution. I tried a separate class library for the Entity Model but it did not work. So i thought i'd simplify things but it still doesn't work.
Let me know if you need anything else. Thanks!
This is my controller file: I added everything in the file just to be on the safe side. the first action method is the only one i use.
CustomerController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ClaimsManagement2.Models;
namespace ClaimsManagement2.Controllers
{
public class CustomerController : Controller
{
//
// GET: /Customer/
public ActionResult Index()
{
ClaimsManagementContext customerContext = new ClaimsManagementContext()
IEnumerable<Customer> customer = customerContext.Customers.ToList();
return View(customer);
}
//
// GET: /Customer/Details/5
public ActionResult Details(int id)
{
return View();
}
//
// GET: /Customer/Create
public ActionResult Create()
{
return View();
}
//
// POST: /Customer/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /Customer/Edit/5
public ActionResult Edit(int id)
{
return View();
}
//
// POST: /Customer/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /Customer/Delete/5
public ActionResult Delete(int id)
{
return View();
}
//
// POST: /Customer/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
// TODO: Add delete logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}
Index.cshtml file
@model IEnumerable<ClaimsManagement2.Models.Customer.>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.AgentID)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.AgentID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.CustomerID }) |
@Html.ActionLink("Details", "Details", new { id=item.CustomerID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.CustomerID })
</td>
</tr>
}
</table>
ClaimsManagementContext.cs
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace ClaimsManagement2.Models
{
public class ClaimsManagementContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
}
}
Customer.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations.Schema;
namespace ClaimsManagement2.Models
{
[Table("Customers")]
public class Customer
{
public int CustomerID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int AgentID { get; set; }
public string Email { get; set; }
}
}
Aside from giving you a script of the database itself, i can't think of anything else to give you.
List<T>
isIEnumerable<T>
so you must have different types involved – user3559349