c# - The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[]', but this dictionary requires a model item of type '' -
here view viewmodel:-
@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>
here controller:-
public actionresult test1() { var jobs=db.job_det.tolist(); return view(jobs); } public actionresult test2() { db.job_applied.tolist(); return view("test1"); }
here viewmodel:-
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; } }
what problem in code?.i m passing 2 models in 1 view using viewmodel, need display 2 lists in 1 view..
try
var jobs = db.job_det.tolist(); var jobapplied = db.job_applied.include(x => x.job_det).tolist(); jobdetailandapplymodel model = new jobdetailandapplymodel() { jobdetail = jobs, jobapplied = jobapplied } return view(model);
also, not sure if make difference replace
@html.displayfor(modelitem => item.job_det.job_title)
with
@item.job_det.job_title
Comments
Post a Comment