Привет, ребята я новичок в ASP.NET в MVC, я получаю ошибки, пожалуйста, решить эту
Мои модели и просмотр модели
public class StudentViewModel { [Key] public int StudentID { get; set; } [StringLength(50)] public string FirstName { get; set; } [StringLength(50)] public string LastName { get; set; } [StringLength(50)] public string FatherName { get; set; } [StringLength(300)] public string Address { get; set; } public DateTime DOB { get; set; } [StringLength(1)] public char Gender { get; set; } [StringLength(1)] public char caste { get; set; } [StringLength(11)] public string MobileNo { get; set; } [StringLength(100)] public string CourseName { get; set; } [StringLength(50)] public string Duration { get; set; } [StringLength(50)] public string Timing { get; set; } public String Institute { get; set; } public int HighestQualification { get; set; } public string Standard { get; set; } [StringLength(100)] public string Subject { get; set; } [StringLength(100)] public string SchoolName { get; set; } public virtual List<Student_Computer> ComputerStudents { get; set; } public virtual List<Student_tution > TutionStudents { get; set; } }
[Table("ComputerStudent")] public class Student_Computer { [Key] public int StudentID { get; set; } [StringLength (50)] public string FirstName { get; set; } [StringLength(50)] public string LastName { get; set; } [StringLength(50)] public string FatherName { get; set; } [StringLength(300)] public string Address { get; set; } public DateTime DOB { get; set; } [StringLength(1)] public char Gender { get; set; } [StringLength(1)] public char caste { get; set; } [StringLength(11)] public string MobileNo { get; set; } [StringLength(100)] public string CourseName { get; set; } [StringLength(50)] public string Duration { get; set; } [StringLength(50)] public string Timing { get; set; } public String Institute { get; set; } public int HighestQualification { get; set; } }
[Table("TutionStudent")] public class Student_tution { [Key] public int StudentID { get; set; } [StringLength(50)] public string FirstName { get; set; } [StringLength(50)] public string LastName { get; set; } [StringLength(50)] public string FatherName { get; set; } [StringLength(300)] public string Address { get; set; } public DateTime DOB { get; set; } [StringLength(1)] public char Gender { get; set; } [StringLength(1)] public char caste { get; set; } [StringLength(11)] public string MobileNo { get; set; } [StringLength(10)] public string Standard { get; set; } [StringLength(100)] public string Subject { get; set; } [StringLength(100)] public string SchoolName { get; set; } [StringLength(50)] public string Timing { get; set; } }
Мой DBCONTEXT
public class StudentDBContext :DbContext { public StudentDBContext() : base("name=MultisoftEntities") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { throw new UnintentionalCodeFirstException(); } public virtual DbSet<Student_Computer> Student_Computer { get; set; } public virtual DbSet<Student_tution> Student_tution { get; set; } public System.Data.Entity.DbSet<Real_MUlti.Models.StudentViewModel> StudentViewModels { get; set; } }
Мой контроллер
public class StudentViewModelsController : Controller { private StudentDBContext db = new StudentDBContext(); // GET: StudentViewModels public ActionResult Index() { StudentViewModel student = new StudentViewModel(); return View(db.StudentViewModels.ToList()); }
Мой взгляд
@model IEnumerable<Real_MUlti.Models.StudentViewModel> @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Index</h2> <p> @Html.ActionLink("Create New", "Create") </p> <table class="table"> <tr> <th> @Html.DisplayNameFor(model => model.FirstName) </th> <th> @Html.DisplayNameFor(model => model.LastName) </th> <th> @Html.DisplayNameFor(model => model.FatherName) </th> <th> @Html.DisplayNameFor(model => model.Address) </th> <th> @Html.DisplayNameFor(model => model.DOB) </th> <th> @Html.DisplayNameFor(model => model.MobileNo) </th> <th> @Html.DisplayNameFor(model => model.CourseName) </th> <th> @Html.DisplayNameFor(model => model.Duration) </th> <th> @Html.DisplayNameFor(model => model.Timing) </th> <th> @Html.DisplayNameFor(model => model.Institute) </th> <th> @Html.DisplayNameFor(model => model.HighestQualification) </th> <th> @Html.DisplayNameFor(model => model.Standard) </th> <th> @Html.DisplayNameFor(model => model.Subject) </th> <th> @Html.DisplayNameFor(model => model.SchoolName) </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.FatherName) </td> <td> @Html.DisplayFor(modelItem => item.Address) </td> <td> @Html.DisplayFor(modelItem => item.DOB) </td> <td> @Html.DisplayFor(modelItem => item.MobileNo) </td> <td> @Html.DisplayFor(modelItem => item.CourseName) </td> <td> @Html.DisplayFor(modelItem => item.Duration) </td> <td> @Html.DisplayFor(modelItem => item.Timing) </td> <td> @Html.DisplayFor(modelItem => item.Institute) </td> <td> @Html.DisplayFor(modelItem => item.HighestQualification) </td> <td> @Html.DisplayFor(modelItem => item.Standard) </td> <td> @Html.DisplayFor(modelItem => item.Subject) </td> <td> @Html.DisplayFor(modelItem => item.SchoolName) </td> <td> @Html.ActionLink("Edit", "Edit", new { id=item.StudentID }) | @Html.ActionLink("Details", "Details", new { id=item.StudentID }) | @Html.ActionLink("Delete", "Delete", new { id=item.StudentID }) </td> </tr> } </table>
ошибка
Что я уже пробовал:
Я получаю ошибку исключения типа "система".InvalidOperationException ' произошло в EntityFramework.dll, но не был обработан в пользовательском коде
Дополнительная информация: тип сущности StudentViewModel не является частью модели для текущего контекста.
[no name]
Узнайте, как использовать отладчик.