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