Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I have a link in a Macro Partial.
<a href='@ChangeLanguage("sv-SE")'>SV</a>
How do I invoke a method like this?
public void ChangeLanguage(string lang) { Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang); Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang); }
There's a couple of options.
The quick'n'dirty version would be to have your href pass in a query string with the language name, so something like:
<a href='./?lang=sv-SE'>SV</a>
Then in your script you'd see if a query string is passed in and call your function:
if (!String.IsNullOrEmpty(Request.QueryString["lang"])) { var lang = Request.QueryString["lang"]; // call your function ChangeLanguage(lang); }
In razor you can create a functions area you just for functions like this:
@functions { public void ChangeLanguage(string lang) { Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang); Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang); } }
You'd want to maybe check the querystring lang is a valid language first.
A nice way would be to maybe use a custom render controller to access the request and change the culture there - see https://our.umbraco.com/Documentation/Reference/Routing/custom-controllers
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Call function from link in razor
Hi,
I have a link in a Macro Partial.
How do I invoke a method like this?
There's a couple of options.
The quick'n'dirty version would be to have your href pass in a query string with the language name, so something like:
Then in your script you'd see if a query string is passed in and call your function:
In razor you can create a functions area you just for functions like this:
You'd want to maybe check the querystring lang is a valid language first.
A nice way would be to maybe use a custom render controller to access the request and change the culture there - see https://our.umbraco.com/Documentation/Reference/Routing/custom-controllers
is working on a reply...