Как решить эту проблему?
Привет Команда
У меня есть контроллер, и я создал для него представление. Я использую DbContext "eNtsaRegistration и у него есть определение таблицы "TbTrainingRegForm. Я хочу сохранить поля формы с помощью списка. Теперь я получаю это исключение "
System.InvalidOperationException: 'The model backing the 'eNtsaRegistration' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).'"
Что я уже пробовал:
<pre> // GET://Home/Save public ActionResult SaveRegForm() { ViewBag.Message = "Details saved successfull"; return View(db.TrainingRegs.ToList()); }
/ Каталог / ООО
public class eNtsaRegistration:DbContext { public eNtsaRegistration() : base("eNtsaRegistration") { } public DbSet<TrainingRegForm> TrainingRegs { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); } }
// Модель
namespace eNtsaRegistrationTraining.Models { public class TrainingRegForm { [Key] public Guid? Id { get; set; } public string Title { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Position { get; set; } public string Company { get; set; } public string StreetAddress { get; set; } public string StreetAddressLine { get; set; } public string City { get; set; } public string StateProvince { get; set; } public int ZipCode { get; set; } public string Country { get; set; } public string Email { get; set; } [Required(ErrorMessage = "This field is required")] [DataType(DataType.PhoneNumber)] public string CellNumber { get; set; } public string DietaryRequirement { get; set; } } public class RegViewAndRoleViewModel { public DietViewModel DietMain { get; set; } public TrainingRegForm RegForm { get; set; } public DropDownViewModel ListCountries { get; set; } public RegistrationTrainingForm HomeModel { get; set; } public RoleViewModel RoleViewModelData { get; set; } }
@model IEnumerable<eNtsaRegistrationTraining.Models.TrainingRegForm> @{ ViewBag.Title = "SaveRegForm"; } <h2>SaveRegForm</h2> <p> @Html.ActionLink("Create New", "Create") </p> <table class="table"> <tr> <th> @Html.DisplayNameFor(model => model.Title) </th> <th> @Html.DisplayNameFor(model => model.FirstName) </th> <th> @Html.DisplayNameFor(model => model.LastName) </th> <th> @Html.DisplayNameFor(model => model.Position) </th> <th> @Html.DisplayNameFor(model => model.Company) </th> <th> @Html.DisplayNameFor(model => model.StreetAddress) </th> <th> @Html.DisplayNameFor(model => model.StreetAddressLine) </th> <th> @Html.DisplayNameFor(model => model.City) </th> <th> @Html.DisplayNameFor(model => model.StateProvince) </th> <th> @Html.DisplayNameFor(model => model.ZipCode) </th> <th> @Html.DisplayNameFor(model => model.Country) </th> <th> @Html.DisplayNameFor(model => model.Email) </th> <th> @Html.DisplayNameFor(model => model.CellNumber) </th> <th> @Html.DisplayNameFor(model => model.DietaryRequirement) </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.Title) </td> <td> @Html.DisplayFor(modelItem => item.FirstName) </td> <td> @Html.DisplayFor(modelItem => item.LastName) </td> <td> @Html.DisplayFor(modelItem => item.Position) </td> <td> @Html.DisplayFor(modelItem => item.Company) </td> <td> @Html.DisplayFor(modelItem => item.StreetAddress) </td> <td> @Html.DisplayFor(modelItem => item.StreetAddressLine) </td> <td> @Html.DisplayFor(modelItem => item.City) </td> <td> @Html.DisplayFor(modelItem => item.StateProvince) </td> <td> @Html.DisplayFor(modelItem => item.ZipCode) </td> <td> @Html.DisplayFor(modelItem => item.Country) </td> <td> @Html.DisplayFor(modelItem => item.Email) </td> <td> @Html.DisplayFor(modelItem => item.CellNumber) </td> <td> @Html.DisplayFor(modelItem => item.DietaryRequirement) </td> <td> @Html.ActionLink("Edit", "Edit", new { id=item.Id }) </td> </tr> } </table>