在控制器asp.net

编程入门 行业动态 更新时间:2024-10-24 12:25:40
本文介绍了在控制器asp-core中获取当前区域性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经为我的视图设置了区域性,并在控制器中更改了区域性,但是我似乎找不到如何知道控制器中当前正在使用的区域性,我正在寻找类似的东西:

I have setup the cultures for my views and changing the culture in a controller but I can't seem to find how to know what culture I'm currently using in a controller, I'm looking for something like:

public class HomeController : Controller { public async Task<IActionResult> Index() { // Something like the next line var requestCulture = GetRequestedCulture() return View(); } }

推荐答案

答案在请求对象上,这里是代码:

The answer was on the Request Object, here's the code:

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(); }

更多推荐

在控制器asp.net

本文发布于:2023-11-16 18:38:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606813.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器   asp   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!