Question 85


2.3.2 Question

Multiple Choice

You are creating an ASP.NET MVC web application. The application accepts phone number input through the application’s form. When viewing the source from a browser, you find the following code:

PhoneNumber: <input id="phoneNumber" name="phoneNumber" size="10" type="text" value="" />

What Razor syntax code segment was used?

  • A. PhoneNumber: <input id="phoneNumber" name="phoneNumber" size="10" type="text" value="3125551212" />
  • B. <div class="editor-field">
    @Html.EditorFor(model => model.PhoneNumber)
    </div>
  • C. PhoneNumber: @Html.TextBox("phoneNumber", Request["phoneNumber"], new { @placeholder = "3125551212" })
  • D. PhoneNumber: @Html.TextBox("phoneNumber", Request["phoneNumber"], new { size = 10 })

Answer:

D
Explanation
A. Incorrect: The Value construct sets the display information in the element. In addi­tion, the field is not bound to the model.
B. Incorrect: This will not validate or set the size requirement.
C. Incorrect: This will make the input field display with a placeholder.
D. Correct: This is the proper way to limit the size of a certain field that is being bound to the model.