I have the following scenario: Calendar page that loads the initial sale nodes from last 2 months. This page has a Load more button that fetches more Sale<
EDIT: Added fixed implementation.
I was able to resolve the issue by setting the CultureInfo
before returning the PartialView
like so: System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture)
The action method looks like this:
public ActionResult LoadMoreSales(int months = 0, string culture = "")
{
// Set the 'CultureInfo' to perserve 'UmbracoContext' when performing an AJAX call
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
if (Request.IsAjaxRequest())
{
if (Request.QueryString["department"] == null)
{
return PartialView("Calendar/_Sales", GetSales(0, months));
}
else
{
int depId = 0;
Int32.TryParse(Request.QueryString["department"], out depId);
return PartialView("Calendar/_Sales", GetSales(depId, months));
}
}
else
{
return PartialView("Calendar/_Sales");
}
}
I have added the hidden cultureInfo
tag in the .cshtml
:
<div id="cultureInfo" hidden>@System.Threading.Thread.CurrentThread.CurrentCulture</div>
The jQuery was also modified to read and pass the hidden value to the controllers action like so:
var cultureInfo = $('#cultureInfo').html();
$.get("/umbraco/surface/Calendar/LoadMoreSales?months=" + months + "&culture=" + cultureInfo, function (data) {
if (data != '') {
$("#saleList").append(data);
}
else {
months = -1;
$("#saleList").append('No more news to display');
}
_inCallback = false;
$('div#loading').empty();
});
There was no need to change .cshtml
file, the dictionary values are being loaded correctly.
Marko,
This was in v6 but similar issue, so in the partial i did
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); Regards
Ismail