我已经为我的视图设置了文化并更改了控制器中的文化,但我似乎无法找到如何知道我当前在控制器中使用的文化,我正在寻找类似的内容:
public class HomeController : Controller {
public async Task<IActionResult> Index()
{
// Something like the next line
var requestCulture = GetRequestedCulture()
return View();
}
}
答案在请求对象上,代码如下:
public async Task<IActionResult> Index() {
// Retrieves the requested culture
var rqf = Request.HttpContext.Features.Get<IRequestCultureFeature>();
// Culture contains the information of the requested culture
var culture = rqf.RequestCulture.Culture;
return View();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)