C# 传入字典的模型项的类型为'';,但本词典需要类型为';System.Collections.Generic.IEnumerabl[],

C# 传入字典的模型项的类型为'';,但本词典需要类型为';System.Collections.Generic.IEnumerabl[],,c#,asp.net-mvc,dictionary,C#,Asp.net Mvc,Dictionary,以下是我的看法: @model IEnumerable<_24By7CallAndBPOPvtLtd.Models.Job_DetailModel> @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Current Jobs</h2> <table class="table table-striped"> <tr>

以下是我的看法:

@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>
这是我的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; }
}
公共类作业\u详细模型
{
public int Job_ID{get;set;}
公共字符串作业标题{get;set;}
公共字符串min_教育{get;set;}
公共字符串作业描述{get;set;}
公共字符串责任{get;set;}
公共字符串位置{get;set;}
公共字符串作业_Shift{get;set;}
公共字符串作业类型{get;set;}
公共可空位置{get;set;}
公共可空年龄{get;set;}
公共字符串{get;set;}
公共字符串经验{get;set;}
public int Deptt_ID{get;set;}
公共可为空的发布日期{get;set;}
在{get;set;}之前可为公共空的Apply_
公共字符串过帐_时间戳{get;set;}
公共可空性别_id{get;set;}
公共虚拟部门部门{get;set;}
公共虚拟性别性别{get;set;}
}
我想使用弹出窗口查看作业的详细信息,但我得到了以下错误

System.InvalidOperationException:传递到字典中的模型项的类型为“\u 24By7CallAndBPOPvtLtd.Models.Job\u DetailModel”,但此字典需要“System.Collections.Generic.IEnumerable”1[\u 24By7CallAndBPOPvtLtd.Models.Job\u Deta”类型的模型项‌​“模型]”


请告诉我如何调用局部视图,因为我正在使用视图模型。

您的索引操作没有任何意义。应该是

 public ActionResult Index()
 {
        var jobs = db.Job_Det.ToList();
        return View(jobs);
 }

您正在视图中使用@model IEnumerable,这表明视图所需的模型类型为IEnumerable。 要避免此错误,请按此方式传递模型以查看:

@model\u 24By7CallAndBPOPvtLtd.Models.Job\u DetailModel


或者将_24By7CallAndBPOPvtLtd.Models.Job_DetailModel的IEnumerable作为模型传递给控制器中的视图。

抛出的错误是哪一行?我不知道..给出下面的错误。。。System.InvalidOperationException:传递到字典中的模型项的类型为“\u 24By7CallAndBPOPvtLtd.Models.Job\u DetailModel”,但此字典需要类型为“System.Collections.Generic.IEnumerable`1[\u 24By7CallAndBPOPvtLtd.Models.Job\u DetailModel]”的模型项。我知道这一点,但如果你下去看到我正在调用的partialview,这是主要的问题,我得到..它给出了与以前相同的错误..我已经尝试了..我正在为弹出窗口在相同的视图中调用partialview。。
 public ActionResult Index()
 {
        var jobs = db.Job_Det.ToList();
        return View(jobs);
 }