Reputation: 1
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include="Id,Reciever_Area,Parcel_Type,Delivery_Type,Parcel_Weight,Final_Cost")] quotation quotation)
{
if (ModelState.IsValid)
{
db.quotations.Add(quotation); <-- this isn't working
db.SaveChanges();
return RedirectToAction("Index", "Home");
}
return View(quotation);
}
This is the error message I get:
An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code
Additional information: The entity type quotation is not part of the model for the current context.
Upvotes: 0
Views: 36
Reputation: 4443
Since the quotation object is not created in the current dbContext thus you've to attach it before adding it.
db.quotations.Attach(quotation);
db.quotations.Add(quotation);
Upvotes: 1