2015-05-26 33 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

你傳入的單個對象到您的視圖InsuredIndex.cshtml必須包含如下定義:

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

(或IEnumerable衍生的集合)

要麼改變你的FeeSchedule_CCGNInsured視圖中使用的FeeSchedule_CCGNInsured單個實例或更新您的迴轉發要刪除視圖你提到:

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

哈抱歉,我是指向錯誤的觀點.... – Tsukasa

+0

@Tsukasa沒有probs,只知道,因爲我去過很多次。 :) – hutchonoid