我总是收到上述错误。
我重新创建了Front Model和Front Controller,但我收到了同样的问题。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Module1.Models
{
public class Front
{
public int FrontId { get; set; }
public int ModuleId { get; set; }
public string Description { get; set; }
public string Code { get; set; }
public int TotalHrs { get; set; }
public int LectHrs { get; set; }
public int TutHrs { get; set; }
public int PracHrs { get; set; }
public int Year { get; set; }
public string Prerequisite { get; set; }
public virtual Module Module { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Module1.Models;
namespace Module1.Controllers
{
public class FrontController : Controller
{
private SchoolEntities db = new SchoolEntities();
//
// GET: /Topic/
public ViewResult Index()
{
var fronts = db.Fronts.Include(t => t.Module);
return View(fronts.ToList());
}
//
// GET: /Topic/Details/5
public ViewResult Details(int id)
{
var mod = db.Modules.Include("Fronts").Single(t => t.ModuleId == id);
return View(mod);
}
//
// GET: /Topic/Create
public ActionResult Create(int ID)
{
var modules = db.Modules.Where(m => m.ModuleId == ID).FirstOrDefault();
if (modules != null)
{
ViewBag.Code = modules.Code;
ViewBag.Description = modules.Description;
}
Front model = new Front();
model.ModuleId = ID;
return View(model);
}
//
// POST: /Topic/Create
[HttpPost]
public ActionResult Create(Front front)
{
if (ModelState.IsValid)
{
db.Fronts.Add(front);
db.SaveChanges();
return RedirectToAction("Details", new { id = front.ModuleId });
}
ViewBag.ModuleId = new SelectList(db.Modules, "ModuleId", "Code", front.ModuleId);
return View(front);
}
//
// GET: /Topic/Edit/5
public ActionResult Edit(int id)
{
var modules = db.Modules.Where(m => m.ModuleId == id).FirstOrDefault();
if (modules != null)
{
ViewBag.Code = modules.Code;
ViewBag.Description = modules.Description;
}
Front front = db.Fronts.Find(id);
ViewBag.ModuleId = new SelectList(db.Modules, "ModuleId", "Code", front.ModuleId);
return View(front);
}
//
// POST: /Topic/Edit/5
[HttpPost]
public ActionResult Edit(Front front)
{
if (ModelState.IsValid)
{
db.Entry(front).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Details", new { id = front.ModuleId });
}
ViewBag.ModuleId = new SelectList(db.Modules, "ModuleId", "Code", front.ModuleId);
return View(front);
}
//
// GET: /Topic/Delete/5
public ActionResult Delete(int id)
{
Front front = db.Fronts.Find(id);
return View(front);
}
//
// POST: /Topic/Delete/5
[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(int id)
{
Front front = db.Fronts.Find(id);
db.Fronts.Remove(front);
db.SaveChanges();
return RedirectToAction("Details", new { id = front.ModuleId });
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
上述错误在进入我的
时弹出
@model Module1.Models.Front
@{
ViewBag.Title = "Details";
}
<h2>Details</h2>
<fieldset>
<legend>Front</legend>
<div class="display-label">Module</div>
<div class="display-field">
@Html.DisplayFor(model => model.Module.Code)
</div>
<div class="display-label">ModuleName</div>
<div class="display-field">
@Html.DisplayFor(model => model.Description)
</div>
<div class="display-label">ModuleCode</div>
<div class="display-field">
@Html.DisplayFor(model => model.Code)
</div>
<div class="display-label">TotalHrs</div>
<div class="display-field">
@Html.DisplayFor(model => model.TotalHrs)
</div>
<div class="display-label">LectHrs</div>
<div class="display-field">
@Html.DisplayFor(model => model.LectHrs)
</div>
<div class="display-label">TutHrs</div>
<div class="display-field">
@Html.DisplayFor(model => model.TutHrs)
</div>
<div class="display-label">PracHrs</div>
<div class="display-field">
@Html.DisplayFor(model => model.PracHrs)
</div>
<div class="display-label">Year</div>
<div class="display-field">
@Html.DisplayFor(model => model.Year)
</div>
<div class="display-label">Prerequisite</div>
<div class="display-field">
@Html.DisplayFor(model => model.Prerequisite)
</div>
</fieldset>
<p>
@Html.ActionLink("Edit", "Edit", new { id=Model.FrontId }) |
@Html.ActionLink("Back to List", "Index")
</p>
<p>
@Html.ActionLink("Add Record", "Create", new { id = Model.ModuleId})
</p>
<p>
@Html.ActionLink("Back to Home", "Index", "SchoolManager")
</p>
我的错误
列名无效。 [节点名称(如果有)= Extent2,Column name = Course_CourseId]