Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a custom ValueProvider in ASP.NET Core

Tags:

asp.net-core

In the old MVC version there is a ValueProviderFactory, but in MVC6, I can't find that factory. How could I define custom valueProvider in MVC6?

like image 343
AllenMa Avatar asked Jan 08 '16 08:01

AllenMa


People also ask

How do I bind a model to view in MVC core?

How does model binding work in ASP.NET Core MVC. In an empty project, change Startup class to add services and middleware for MVC. Add the following code to HomeController, demonstrating binding of simple types. Add the following code to HomeController, demonstrating binding of complex types.

What is bind property in C#?

The Binding class is used to bind a property of a control with the property of an object. For creating a Binding object, the developer must specify the property of the control, the data source, and the table field to which the given property will be bound.


1 Answers

You can add the factory in the ConfigureServices method on your Startup class.

services.Configure<MvcOptions>(options => {
    options.ValueProviderFactories.Add(new CustomValueProviderFactory());
});
like image 189
Robert Massa Avatar answered Sep 17 '22 13:09

Robert Massa