Проблема виникає через неспівпадіння типів моделей, переданих у представлення, і типів моделей, очікуваних у контролері. Це часто виникає, коли тип моделі, що передається в представлення, відрізняється від типу моделі, який очікується в представленні. Давайте розглянемо рішення для вирішення цієї проблеми на прикладі коду ASP.NET MVC.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Why am I getting the error "The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.Tbl_Registration_F260DE.....', getting an error The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.Tbl_Registration_F260DE0649B1F8A99D1E75ED9548854811A0E22A5BE146F4EF69B9A7DB65ED97', but this dictionary requires a model item of type 'BTK_ES.Models.Tbl_Notification'. How can I solve it below Is my code I just want to show user data in input fields so the user can edit? [HttpGet] public ActionResult StudentDetails(int Registration_ID) { var result = dbContext.Tbl_Registration.Where(move => move.Registration_ID == Registration_ID).FirstOrDefault(); if (result != null) { ViewBag.Class_ID = dbContext.Tbl_Class .Select(c => new SelectListItem { Value = c.Class_ID.ToString(), Text = c.Class_Name }) .ToList(); return View(result); } else { return HttpNotFound(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
and this is the code of my view @model BTK_ES.Models.Tbl_Registration @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h5>Tbl_Registration</h5> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) @Html.HiddenFor(model => model.Registration_ID) <div class="form-group"> @Html.LabelFor(model => model.NameOfApplicant, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.NameOfApplicant, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.NameOfApplicant, "", new { @class = "text-danger" }) </div> </div> </div> } @section Scripts { @Scripts.Render("~/bundles/jqueryval") } |