if i browse to http://mysite.com/us/products, in the razor view I can then get a list of product nodes, all with the correct culture-specific URLs. eg.
However, if I want to implement a product-search feature, which uses jquery to call a SurfaceController action to return a list of products in a partial view, the SurfaceController has no concept of the current culture, so I get a list of products all with URLs set as (i think) the first domain/culture that umbraco can find (UK in this case)
How can I tell umbraco to give me a content URL specific to a certain culture (in this case, I'd want it to be the culture of the page that is making the ajax/surface request)?
This seems like a pretty common scenario; anybody using culture url's who is making SurfaceController or WebApi requests for content items will face this problem, but I can't find any documentation on it
Hi, you can always send current lang from document template to surface controller:
// in document template razor
string currentLang = Model.Content.GetCulture().TwoLetterISOLanguageName;
// call to surface controller
Url.Action("DoSomething", "MySurface", new { lang = currentLang })
// surface controller
public ActionResult DoSomething(string lang)
{
// set culture
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(lang);
// call partial view with the same culture as in document template
return PartialView("~/Views/Partials/SomePartial.cshtml", model);
}
Getting a culture specific content URL from SurfaceController or WebApi
I have a site set up with multiple cultures and host-names at the root, eg.
http://mysite.com/uk
http://mysite.com/us
http://mysite.com/au
if i browse to http://mysite.com/us/products, in the razor view I can then get a list of product nodes, all with the correct culture-specific URLs. eg.
each one has the correct URL for the page culture, eg:
http://mysite.com/us/products/product-1
However, if I want to implement a product-search feature, which uses jquery to call a SurfaceController action to return a list of products in a partial view, the SurfaceController has no concept of the current culture, so I get a list of products all with URLs set as (i think) the first domain/culture that umbraco can find (UK in this case)
eg.
http://mysite.com/uk/products/product-1
How can I tell umbraco to give me a content URL specific to a certain culture (in this case, I'd want it to be the culture of the page that is making the ajax/surface request)?
This seems like a pretty common scenario; anybody using culture url's who is making SurfaceController or WebApi requests for content items will face this problem, but I can't find any documentation on it
Hello there,
Did you find any solution to this ?
Thank you!
yes - would like to know best practice here too :)
Hi, you can always send current lang from document template to surface controller:
Regards
is working on a reply...