以下是我的观点:
@model IEnumerable<_24By7CallAndBPOPvtLtd.Models.Job_DetailModel>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Current Jobs</h2>
<table class="table table-striped">
<tr>
<th>Job Title</th>
<th>Location</th>
....
<th>Action</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>@Html.DisplayFor(modelItem => item.job_title)</td>
<td>@Html.DisplayFor(modelItem => item.Location)</td>
....
<td>
<button type="button" id="detail" onclick="location.href='@Url.Action("Details", new { id = item.Job_ID })'" data-toggle="modal" data-target=".JobDetailModel">Detail</button>
</td>
</tr>
}
</table>
<div class="modal fade JobDetailModel" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg">
<div class="modal-content">
@Html.Partial("~/Views/MainDashboard/_Details.cshtml")
</div>
</div>
</div>
这是我的控制器: -
public ActionResult Index(Job_DetailModel jvm)
{
db.Job_Det.ToList();
return View(jvm);
}
public ActionResult Details(int? id)
{
Job_Det jobdetail = db.Job_Det.Find(id);
if (jobdetail == null)
{
return HttpNotFound();
}
return View(jobdetail);
}
这是我的ViewModel: -
public class Job_Detail Model
{
public int Job_ID { get; set; }
public string job_title { get; set; }
public string min_education { get; set; }
public string job_description { get; set; }
public string Responsibilities { get; set; }
public string Location { get; set; }
public string Job_Shift { get; set; }
public string Job_Type { get; set; }
public Nullable<int> Positions { get; set; }
public Nullable<int> Age { get; set; }
public string Career_Level { get; set; }
public string Experience { get; set; }
public int Deptt_ID { get; set; }
public Nullable<System.DateTime> Posted_Date { get; set; }
public Nullable<System.DateTime> Apply_Before { get; set; }
public string posting_timestamp { get; set; }
public Nullable<int> Gender_id { get; set; }
public virtual Department Department { get; set; }
public virtual Gender Gender { get; set; }
}
我想使用弹出窗口显示作业的详细信息,但是我收到了以下错误。
System.InvalidOperationException:传递到字典中的模型项的类型为'_24By7CallAndBPOPvtLtd.Models.Job_DetailModel',但此字典需要类型为'System.Collections.Generic.IEnumerable'1的模型项[_24By7CallAndBPOPvtLtd.Models.Job_Deta ilModel]”。
请告诉我如何调用部分视图,因为我正在使用视图模型。
答案 0 :(得分:1)
你的索引动作没有任何意义。应该是......?
public ActionResult Index()
{
var jobs = db.Job_Det.ToList();
return View(jobs);
}
答案 1 :(得分:0)
您正在使用@model IEnumerable&lt;&gt;在您的视图中,表明View所期望的模型是IEnumerable类型。 要避免此错误,请将模型传递给以下内容进行查看:
@model _24By7CallAndBPOPvtLtd.Models.Job_DetailModel
或将IEnumerable的_24By7CallAndBPOPvtLtd.Models.Job_DetailModel作为模型传递给控制器中的视图。