In this recipe, you will learn what a value provider is, and how to use it.
We will create an ASP.NET Core MVC Web Application template by going to File
| New
| Project
| AspNet Core Web Application (.Net Framework)
| Web Application
.
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.
- Let's start by creating a
ValueProvider
class that inherits fromIValueProvider
. This class will implement two methods fromIValueProvider
:bool ContainsPrefix(string prefix)
, this method tells us whether theValueProvider
is able to return...