In MVC5, I used to obtain a ValueProvider
within a Controller Action like this:
public class ConfigurationsController : Controller
{
public ActionResult Index()
{
var valueProvider = this.ValueProvider;
var someValue = valueProvider.GetValue("someKey");
return View();
}
}
But it seems to be gone in Asp.NET Core 1.0. Is there a way to get the ValueProvider
in the new version?
Thanks in advance
You can create a CompositeValueProvider
using ControllerContext
.
var valueProvider = await CompositeValueProvider.CreateAsync(ControllerContext);
CompositeValueProvider represents Microsoft.AspNetCore.Mvc.ModelBinding.IValueProvider whose values come from a collection of Microsoft.AspNetCore.Mvc.ModelBinding.IValueProviders.
Example
[HttpPost]
public async Task<IActionResult> SomeAction()
{
var valueProvider = await CompositeValueProvider.CreateAsync(ControllerContext);
var someValue = valueProvider.GetValue("foo");
return View();
}