如何在 asp.net core 1.0 中获取 valueprovider?
How can I get valueprovider in asp.net core 1.0?
在 MVC5 中,我曾经在这样的控制器操作中获取 ValueProvider
:
public class ConfigurationsController : Controller
{
public ActionResult Index()
{
var valueProvider = this.ValueProvider;
var someValue = valueProvider.GetValue("someKey");
return View();
}
}
但它似乎在 Asp.NET Core 1.0 中消失了。有没有办法在新版本中获得ValueProvider
?
提前致谢
您可以使用 ControllerContext
创建 CompositeValueProvider
。
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.
示例
[HttpPost]
public async Task<IActionResult> SomeAction()
{
var valueProvider = await CompositeValueProvider.CreateAsync(ControllerContext);
var someValue = valueProvider.GetValue("foo");
return View();
}
在 MVC5 中,我曾经在这样的控制器操作中获取 ValueProvider
:
public class ConfigurationsController : Controller
{
public ActionResult Index()
{
var valueProvider = this.ValueProvider;
var someValue = valueProvider.GetValue("someKey");
return View();
}
}
但它似乎在 Asp.NET Core 1.0 中消失了。有没有办法在新版本中获得ValueProvider
?
提前致谢
您可以使用 ControllerContext
创建 CompositeValueProvider
。
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.
示例
[HttpPost]
public async Task<IActionResult> SomeAction()
{
var valueProvider = await CompositeValueProvider.CreateAsync(ControllerContext);
var someValue = valueProvider.GetValue("foo");
return View();
}