How to do it...

The ASP.NET ModelBinding mechanism maps action method parameters to value providers. Value providers can be form data, route data, QueryString, and Files. They can be any data sent through an HTTP request, but not exclusively.

An interesting case to create a custom value provider could be creating a value provider for HTTP headers, cookie values, and so on; however, we could also create a ValueProvider class to retrieve AppSettings, or ConnectionString settings.

  1. Let's start by creating a ValueProvider class that inherits from IValueProvider. This class will implement two methods from IValueProvider:
    • bool ContainsPrefix(string prefix), this method tells us whether the ValueProvider is able to return a value matching a property ...

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.