You are implementing an ASP.NET MVC 2 Web application that contains the following class.
public class DepartmentController : Controller
{
static List<Department> departments =
new List<Department>();
public ActionResult Index()
{
return View(departments);
}
public ActionResult Details(int id)
{
return View(departments.Find(x => x.ID==id));
}
public ActionResult ListEmployees(Department d)
{
List<Employee> employees = GetEmployees(d);
return View(employees);
}}
You create a strongly typed view that displays details for a Department instance. You want the view
to also include a listing of department employees. You need to write a code segment that will call
the ListEmployees action method and output the results in place. Which code segment should you
use?
A.
<%= Html.Action(“ListEmployees”, Model) %>
B.
<%= Html.ActionLink(“ListEmployees”, “Department”,
“DepartmentController”) %>
C.
<% Html.RenderPartial(“ListEmployees”, Model); %>
D.
<%= Html.DisplayForModel(“ListEmployees”) %>
Explanation:
Html.Action(string, object) invokes a child action method and returns the result as an HTML
string.ChildActionExtensions.Action Method
(http://msdn.microsoft.com/en-s/library/system.web.mvc.html.childactionextensions.action.aspx)
Html.DisplayForModel() Method returns HTML markup for each property in the model.
Html.DisplayForModel(string, object) Method returns HTML markup for each property in the model,
using the specified template and additional view data RenderPartialExtensions.RenderPartial
Method
(http://msdn.microsoft.com/enus/
library/system.web.mvc.html.renderpartialextensions.renderpartial.aspx)
The ActionLink method renders an element that links to an action method. LinkExtensions.ActionLink
Method
(http://msdn.microsoft.com/en-us/library/system.web.mvc.html.linkextensions.actionlink.aspx)