编辑 :添加了固定的实现。
我能够通过
CultureInfo在返回之前设置来解决此问题,
PartialView如下所示:
System.Threading.Thread.CurrentThread.CurrentUICulture= new CultureInfo(culture)
动作方法如下:
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"); }}
我在中添加了隐藏
cultureInfo标签
.cshtml:
<div id="cultureInfo" hidden>@System.Threading.Thread.CurrentThread.CurrentCulture</div>
jQuery也进行了修改,以读取隐藏值并将其传递给控制器 *** 作,如下所示:
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(); });
无需更改
.cshtml文件,字典值已正确加载。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)