我尝试创建一个MVC网站,并尝试将SQL数据库与该网站连接起来。在尝试通过网站编辑数据库时,我收到以下错误,
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MVC_Sample.Models
{
public class ThirdController : Controller
{
private Servion_sathiyaEntities db = new Servion_sathiyaEntities();
//
// GET: /Third/
public ActionResult Index()
{
return View(db.ipls.ToList());
}
//
// GET: /Third/Details/5
public ActionResult Details(string id = null)
{
ipl ipl = db.ipls.Find(id);
if (ipl == null)
{
return HttpNotFound();
}
return View(ipl);
}
//
// GET: /Third/Create
public ActionResult Create()
{
return View();
}
//
// POST: /Third/Create
[HttpPost]
public ActionResult Create(ipl ipl)
{
if (ModelState.IsValid)
{
db.ipls.Add(ipl);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(ipl);
}
//
// GET: /Third/Edit/5
public ActionResult Edit(string id = null)
{
ipl ipl = db.ipls.Find(id);
if (ipl == null)
{
return HttpNotFound();
}
return View(ipl);
}
//
// POST: /Third/Edit/5
[HttpPost]
public ActionResult Edit(ipl ipl)
{
if (ModelState.IsValid)
{
db.Entry(ipl).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(ipl);
}
//
// GET: /Third/Delete/5
public ActionResult Delete(string id = null)
{
ipl ipl = db.ipls.Find(id);
if (ipl == null)
{
return HttpNotFound();
}
return View(ipl);
}
//
// POST: /Third/Delete/5
[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(string id)
{
ipl ipl = db.ipls.Find(id);
db.ipls.Remove(ipl);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
}
这就是我的控制器的外观。如果您需要更多详细信息,请与我们联系。