The following is simplified code where an error occurs in the view:
Model:
public class Employee
{
public string EmployeeID{ get; set; }
public string Name { get; set; }
...
}
Controller:
public ActionResult Index()
{
var model = selectAllEmployees();
ViewBag.ITDept = model.Where(a => a.departmentID == 4);
ViewBag.Officer = model.Where(a => a.departmentID == 5);
return View(model);
}
View:
@model IList<EnrolSys.Models.Employee>
@{
Layout = null;
}
@using (Html.BeginForm("Save", "EmployMaster"))
{
for (int i = 0; i < ViewBag.ITDept.Count(); i++)
{
@Html.Partial("EmployeeDisplayControl", ViewBag.ITDept[i])
}
<br />
}
There @Html.Partial("EmployeeDisplayControl", ViewBag.ITDept[i])is an exception in the line :
'System.Web.Mvc.HtmlHelper>' does not have an applicable method named "Partial", but it seems to have an extension method using this name. Extension methods cannot be dynamically sent. Think about how to use dynamic arguments or invoke an extension method without extension method syntax.
I suppose this suggests that I cannot use extension methods in dynamic expression, is there any workaround for this ??
I made a fiddle for this error:
https://dotnetfiddle.net/ekDH06