Which code segment should you use?

You are implementing an ASP.NET MVC 2 Web application that contains the following class.
Public Class DepartmentController
Inherits Controller
Shared departments As List(Of Department) =
New List(Of Department)
Function Index() As ActionResult
Return View(departments)
End Function
Function Details(ByVal id As Integer) As ActionResult
Return View(departments.Find(Function(x) x.ID = id))
End Function
Function ListEmployees(ByVal d As Department) As ActionResult
Dim employees As List(Of Employee) = GetEmployees(d)
Return View (employees)
End Function
End Class
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?

You are implementing an ASP.NET MVC 2 Web application that contains the following class.
Public Class DepartmentController
Inherits Controller
Shared departments As List(Of Department) =
New List(Of Department)
Function Index() As ActionResult
Return View(departments)
End Function
Function Details(ByVal id As Integer) As ActionResult
Return View(departments.Find(Function(x) x.ID = id))
End Function
Function ListEmployees(ByVal d As Department) As ActionResult
Dim employees As List(Of Employee) = GetEmployees(d)
Return View (employees)
End Function
End Class
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/ens/library/system.web.mvc.html.childactio extensions.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)



Leave a Reply 0

Your email address will not be published. Required fields are marked *