栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Umbraco AJAX部分视图控制器操作调用

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Umbraco AJAX部分视图控制器操作调用

编辑 :添加了固定的实现。

我能够通过

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
文件,字典值已正确加载。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/381362.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号