Grab ID or Name of Selected Language within Razor

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 11 ans
Hi guys

So basically as the title of the thread suggests. All I want to know is how I can check what Language is currently selected for the store, so that I can use it in an if statement to display whatever I want based on the selected language.

I would greatly appreciate any help.

Thank You.

Ciwan.
Il y a 11 ans
Add the Language field to your Model and set it with IWorkContext.WorkingLanguage
Il y a 11 ans
Thanks Andy.

When I do, WorkContext returns null ! Here is my code:

public partial class HomeController : BaseNopController
    {
        private readonly IWorkContext _workContext;

        [NopHttpsRequirement(SslRequirement.No)]
        public ActionResult Index()
        {
            var x = _workContext.WorkingLanguage.Id;
            ViewBag.ActiveLanguageId = x;
            return View();
        }
    }
Il y a 11 ans
You need to add it as a dependency in your constructor, similar to services or settings.
Il y a 11 ans
Thank You Andy, that did it :)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.