2015-05-26 5 views
1

Обновление Я указывал на неправильный вид контроллера.Проблема с передаваемой моделью

Не уверен, что мне не хватает, но мой элемент передается - это то, что нужно для модели. При нажатии кнопки «Удалить» для удаления записи.

The model item passed into the dictionary is of type PAL.Intranet.Models.FeeSchedule_CCGNInsured, but this dictionary requires a model item of type System.Collections.Geeric.IEnumerable1[PAL.Intranet.Models.FeeSchedule_CCGNInsured]

Страхователь

@model IEnumerable<PAL.Intranet.Models.FeeSchedule_CCGNInsured> 

@{ 
    ViewBag.Title = "CCGN Insured Fee Schedule"; 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
} 

<link href="~/Content/CSS/MetroButtonWidth.css" rel="stylesheet" /> 

<h2>CCGN Insured Fee Schedule</h2> 
<hr class="bg-dark" /> 

@if (User.IsInRole("Intranet Admins")) 
{ 
    <p> 
     <button class="button small-button info buttonWidth100" onclick="location.href='@Url.Action("CCGNInsuredCreate", "FeeSchedule")'">Create New</button> 
     <br /> 
    </p> 
} 

<table class="table hovered bordered striped border"> 
    <tr> 
     <th class="fg-white bg-dark"> 
      CPT 
     </th> 
     <th class="fg-white bg-dark"> 
      Description 
     </th> 
     <th class="fg-white bg-dark"> 
      Insured Office Fee 
     </th> 
     <th class="fg-white bg-dark"> 
      10% Coin 
     </th> 
     <th class="fg-white bg-dark"> 
      20% Coin 
     </th> 
     <th class="fg-white bg-dark"> 
      30% Coin 
     </th> 
     <th class="fg-white bg-dark"> 
      Insured Non Office Fee 
     </th> 
     <th class="fg-white bg-dark"> 
      10% Coin 
     </th> 
     <th class="fg-white bg-dark"> 
      20% Coin 
     </th> 
     <th class="fg-white bg-dark"> 
      30% Coin 
     </th> 
    </tr> 

@foreach (var item in Model) { 
    <tr> 
     <td class="text-small"> 
      @Html.DisplayFor(modelItem => item.CPT) 
     </td> 
     <td class="text-small"> 
      @Html.DisplayFor(modelItem => item.Description) 
     </td> 
     <td class="text-small"> 
      @Html.DisplayFor(modelItem => item.InsuredOfficeFee) 
     </td> 
     <td class="text-small"> 
      @Html.DisplayFor(modelItem => item.IOF10) 
     </td> 
     <td class="text-small"> 
      @Html.DisplayFor(modelItem => item.IOF20) 
     </td> 
     <td class="text-small"> 
      @Html.DisplayFor(modelItem => item.IOF30) 
     </td> 
     <td class="text-small"> 
      @Html.DisplayFor(modelItem => item.InsuredNonOfficeFee) 
     </td> 
     <td class="text-small"> 
      @Html.DisplayFor(modelItem => item.INOF10) 
     </td> 
     <td class="text-small"> 
      @Html.DisplayFor(modelItem => item.INOF20) 
     </td> 
     <td class="text-small"> 
      @Html.DisplayFor(modelItem => item.INOF30) 
     </td> 

     @if (User.IsInRole("Intranet Admins")) 
     { 
      <td> 
       <button class="button small-button info buttonWidth75" onclick="location.href='@Url.Action("CCGNInsuredEdit", "FeeSchedule", new { id = item.ID })'">Edit</button> 
       <button class="button small-button danger buttonWidth75" onclick="location.href='@Url.Action("CCGNInsuredDelete", "FeeSchedule", new { id = item.ID })'">Delete</button> 
      </td> 
     } 
    </tr> 
} 

</table> 


<button class="button small-button danger buttonWidth75" onclick="location.href='@Url.Action("CCGNInsuredDelete", "FeeSchedule", new { id = item.ID })'">Delete</button> 

Контроллер

public ActionResult CCGNInsuredDelete(Guid? id) 
    { 
     if (id == null) 
     { 
      return new HttpStatusCodeResult(HttpStatusCode.BadRequest); 
     } 
     FeeSchedule_CCGNInsured FeeSchedule_CCGNInsured = db.FeeSchedule_CCGNInsured.Find(id); 
     if (FeeSchedule_CCGNInsured == null) 
     { 
      return HttpNotFound(); 
     } 
     return View("/Views/FeeSchedule/CCGN/InsuredIndex.cshtml", FeeSchedule_CCGNInsured); 
    } 

Удалить Просмотр

@model PAL.Intranet.Models.FeeSchedule_CCGNInsured 
+0

доля ваш InsuredIndex код вид –

ответ

1

Вы передаете один объект из FeeSchedule_CCGNInsured на ваш взгляд InsuredIndex.cshtml, который должен содержать следующее определение:

@model IEnumerable<PAL.Intranet.Models.FeeSchedule_CCGNInsured> 

(или коллекцию, полученную из IEnumerable)

Либо изменить FeeSchedule_CCGNInsured вид использовать один экземпляр FeeSchedule_CCGNInsured или обновить ваше возвращение направить его с точки зрения удаления вы упоминаете:

return View("/Views/FeeSchedule/CCGN/delete.cshtml", FeeSchedule_CCGNInsured); 
+0

Ha жаль, что я указывал на неправильный взгляд .... – Tsukasa

+0

@Tsukasa Нет проблем, знаю только потому, что я был там много раз. :) – hutchonoid

Смежные вопросы