Question 84


2.3.1 Question

Multiple Choice

You are creating an ASP.NET MVC web application. Within the application, you have created a partial view for contact email and phone number. Which code segment should you use to display the partial view on the main page?

  • A. <div class="float-right">
    <section id="contact">
    @Html.ActionLink("ContactPartial")
    </section>
    </div>
  • B. <div class="float-right">
    <section id="contact">
    @Html.Partial("ContactPartial")
    </section>
    </div>
  • C. <div class="float-right">
    <section id="contact">
    @RenderPage("ContactPartial")
    </section>
    </div>
  • D. <div class="float-right">
    <section id="contact">
    @RenderBody("ContactPartial")
    </section>
    </div>

Answer:

B
Explanation
A. Incorrect: @Html.ActionLink creates a link but does not load a partial view.
B. Correct: @Html.Partial loads a partial view.
C. Incorrect: @RenderPage method inserts one complete page into another This is not what you are looking to do as you only want the partial view content to be displayed.
D. Incorrect: @RenderBody inserts views on master layout pages.