這裏是我的視圖模型視圖: -傳遞到字典的模型項的類型爲「System.Collections.Generic.List`1 []」,但本詞典需要類型'的典範項目
@model _24By7CallAndBPOPvtLtd.Models.JobDetailandApplyModel
<table class="table table-striped">
@foreach (var item in Model.jobdetail)
{
<tr>
<td>
@item.job_title
</td>
<td>
<a href="@Url.Action("Edit", new { id = item.Job_ID })"><i class="glyphicon glyphicon-pencil"></i></a>
<a href="@Url.Action("Delete", new { id = item.Job_ID })"><i class="glyphicon glyphicon-remove" style="color:red"></i></a>
</td>
</tr>
}
</table>
<table class="table table-striped">
@foreach (var item in Model.jobapplied)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.User_Account.Full_Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Job_Det.job_title)
</td>
<td>
<a href="/Content/CV/@item.User_CV.Cv_Path" target="_blank">Download</a>
</td>
</tr>
}
</table>
這裏是我的控制器: -
public ActionResult Test1()
{
var jobs=db.Job_Det.ToList();
return View(jobs);
}
public ActionResult Test2()
{
db.Job_Applied.ToList();
return View("Test1");
}
這裏是我的視圖模型: -
public class JobDetailandApplyModel
{
public IEnumerable<Job_Det> jobdetail { get; set; }
public IEnumerable<Job_Applied> jobapplied { get; set; }
}
public partial class Job_Applied
{
public int JobApplied_ID { get; set; }
public int Employeer_ID { get; set; }
public int Job_ID { get; set; }
public int User_ID { get; set; }
public Nullable<int> Cv_Id { get; set; }
public Nullable<int> status_Id { get; set; }
public System.DateTime date_applied { get; set; }
public Nullable<System.TimeSpan> time_applied { get; set; }
public string timestamp_applied { get; set; }
public virtual Employeer Employeer { get; set; }
public virtual Job_Det Job_Det { get; set; }
public virtual Status Status { get; set; }
public virtual User_CV User_CV { get; set; }
public virtual User_Account User_Account { get; set; }
}
什麼是這個代碼的問題.IM傳遞兩個MOD? ELS使用視圖模型,我需要在一個視圖中顯示兩個列表一種觀點..
您正在嘗試將您的列表分配給整個模型。您需要初始化模型,並將值分配給兩個列表中的每一個。 – Andrew
您並未將列表傳遞給'Test2'方法中的視圖。 –