c# - ViewData Int32 must be of type IEnumerable when viewing from stored procedure -
i don't know if because of stored procedure did. error
the viewdata item has key 'department' of type 'system.int32' must of type 'ienumerable'.
here's code :
(view)
<div class="col-lg-4"> <%: html.dropdownlistfor(m => m.department, model.departments, "please select", ((viewbag.role >= 2 && viewbag.role <= 5) ? (object)new { @class="form-control", @onchange="onchangedepartment(this.value);" }:(object)new { @class="form-control", @disabled="disabled" }))%> </div>
(model)
public bool loaddepartmentsfromdb() { workflowentities entity = new workflowentities(); list<selectlistitem> departments = new list<selectlistitem>(); list<selectlistitem> supervisors = new list<selectlistitem>(); foreach (sp_departmentmaster_getall_result sp_depts in entity.sp_departmentmaster_getall()) { departments.add(new selectlistitem { value = sp_depts.departmentid.tostring() , text = sp_depts.departmentname , selected = sp_depts.departmentid == department }); supervisors.add(new selectlistitem { value = sp_depts.supervisorid.tostring() , text = sp_depts.supervisorname , selected = sp_depts.departmentid == department }); if (sp_depts.departmentid == department) this.supervisor = sp_depts.supervisorid; } this.departments = departments; this.supervisors = supervisors; return true; }
did missed ?
added :
public ienumerable<selectlistitem> departments { get; set; }
stored procedure property
public partial class sp_departmentmaster_getall_result { public int departmentid { get; set; } public string departmentname { get; set; } public int supervisorid { get; set; } public string supervisorname { get; set; } }
Comments
Post a Comment