Here's the scenaio, I have an Employee object and a Company object which has a list of employees.
I have Company.aspx
which inherits from ViewPage<Company>
.
In Company.aspx I call
Html.DisplayFor(m => m.Employees).
I have an Employee.ascx
partial view which inherits from ViewUserControl<Employee
> in my DisplayTemplates folder.
Everything works fine and Company.aspx
renders the Employee.ascx
partial for each employee.
Now I have two additional methods on my controller called GetEmployees
and GetEmployee(Id)
.
In the GetEmployee(Id)
action I want to return the markup to display this one employee, and in GetEmployees()
I want to render the markup to display all the employees (these two action methods will be called via AJAX).
In the GetEmployee action I call
return PartialView("DisplayTemplates\Employee", employee)
This works, although I'd prefer something like
return PartialViewFor(employee)
which would determine the view name by convention.
Anwyay, my question is how should I implement the GetEmployees()
action?
I don't want to create any more views, because frankly, I don't see why I should have to.
I've tried the following which fails miserably :)
return Content(New HtmlHelper<IList<Of DebtDto>>(null, null).DisplayFor(m => debts));
However if I could create an instance of an HtmlHelper object in my controller, I suppose I could get it to work, but it feels wrong.
Any ideas? Have i missed something obvious?