Question 101


3.3.3 Question

Multiple Choice

You have been tasked with modernizing an application created in ASP 3.0. Part of one of the pages contains HTML that comes as a string from a third-party application as part of a service call that populates part of a form. The same form contains input values for your application.

You need to support the same business process as the original application, but you also want to use some MVC features. What is the approach?

  • A. Create a single model containing information from your local application. Use strongly-typed binding as much as possible and manually match the rest of the fields.
  • B. Create a single model for the local input fields and the service call input, and use ToValueProvider to map the entire object.
  • C. Create a single model. Use weakly-typed binding for the form fields, and the HTML provided by the third-party application.
  • D. Create a model that contains only your fields and strongly bind the fields to the model. Create a second model that maps to the fields in the imported HTML and bind to that model using ToValueProvider.

Answer:

D
Explanation
A. Incorrect: Although this could conceivably work, it has the misfortune of expect­ing manual mapping. It also uses the approach of a single model, and because the provided HTML input forms might change under you, it makes more sense to use two models so that the information your application controls is not affected.
B. Incorrect: Although this would work, it uses the single model approach. Because the provided HTML input forms can change outside of your own release cycle, it makes more sense to use two models so that the information your application controls is not affected.
C. Incorrect: You cannot weakly bind to the input fields provided from the third party because weakly-bound models imply that you have used an HTML helper to write the information, and you are just giving the helper a hint to the property it should map to in the model.
D. Correct: The key is separating your data input fields from the provided input fields. You can strongly-bind to yours because you have full control over the rela­tionship between your model and your view, and can then use the ToValueProvider to merge the other model that is tied to the provided input fields.