【发布时间】:2015-11-05 06:28:27
【问题描述】:
这是主视图Dept_Manager_Approval.cshtml,我在其中放置了一个模式来显示数据。
<td>
<i title="View Details">
@Ajax.ActionLink(" ", "ViewAccessStatus", new { id = item.request_access_id },
new AjaxOptions
{
HttpMethod = "Get",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "edit-div",
}, new { @class = "fa fa-eye btn btn-success approveModal sample" })</i>
</td>
在这个只是模态的局部视图中,ViewAccessStatus.cshtml,我在这里插入了另一个局部视图。
<div>
<h2><span class ="label label-success">Request Creator</span> </h2>
@if (Model.carf_type == "BATCH CARF")
{
@Html.Partial("Batch_Requestor1", new {id= Model.carf_id })
}else{
<h4><span class ="label label-success">@Html.DisplayFor(model=>model.created_by)</span></h4>
}
</div>
控制器:
public ActionResult Batch_Requestor1(int id = 0)
{
var data = db.Batch_CARF.Where(x => x.carf_id == id && x.active_flag == true).ToList();
return PartialView(data);
}
Batch_Requestor1.cshtml
@model IEnumerable<PETC_CARF.Models.Batch_CARF>
@{
ViewBag.Title = "All Requestors";
}
<br/><br/>
<table class="table table-hover">
<tr class="success">
<th>
@Html.DisplayName("Full Name")
</th>
<th>
@Html.DisplayName("Email Add")
</th>
<th>
@Html.DisplayName("User ID")
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.fname) - @Html.DisplayFor(modelItem => item.lname)
</td>
<td>
@Html.DisplayFor(modelItem => item.email_add)
</td>
<td>
@Html.DisplayFor(modelItem => item.user_id)
</td>
</tr>
}
</table>
当我运行它时,我得到了这个错误
传入字典的模型项的类型为“f__AnonymousType01[System.Int32]”,但此字典需要类型为“System.Collections.Generic.IEnumerable`1[PETC_CARF.Models.Batch_CARF] 的模型项'。
任何想法我将如何插入另一个局部视图?
【问题讨论】:
-
谢谢你。真的很有帮助。
-
实际上,它现在正在工作。谢谢
标签: asp.net-mvc-4 razor asp.net-mvc-partialview