Developing ASP.NET MVC Web Applications — Question 4
You are developing an ASP.NET Core MVC web application.
The application includes a C# type named InsuranceID that represents an insurance policy identifier for a customer. Each instance of InsuranceID is five alphanumeric characters followed by a dash and then four numbers (for example, ab12x-2323).
You need to ensure that Controller actions can accept values of type InsuranceID.
What are two possible ways to achieve this goal? Each correct answer presents a complete solution.
NOTE: Each correct selection is worth one point.
Answer options
- A. Implement the IBinderTypeProviderMetadata interface.
- B. Implement the IModeIBinder interface.
- C. Use a TypeConverter object.
- D. Implement the IBindingSourceMetadata interface.
- E. Implement the ITypeComp interface.
Correct answer: C
Explanation
The correct answer is C, as using a TypeConverter allows for the conversion of the InsuranceID type when binding model data in MVC. Options A, B, D, and E do not provide a direct method for converting the custom type in the context of model binding, making them unsuitable for this purpose.