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.
Hace 11 años
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.
Hace 11 años
Add the Language field to your Model and set it with IWorkContext.WorkingLanguage
Hace 11 años
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();
        }
    }
Hace 11 años
You need to add it as a dependency in your constructor, similar to services or settings.
Hace 11 años
Thank You Andy, that did it :)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.