怎样的CultureInfo传递给partialView为Ajax调用? [英] How to pass CultureInfo to partialView for ajax call?

查看:103
本文介绍了怎样的CultureInfo传递给partialView为Ajax调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的ViewPage和一个partialview。对于默认请求时,页面called-的CultureInfo在基类的ViewPage的设置。我创建这个自定义的基类,它初始化依赖于一个cookie的文化做一些其他的东西为好。有哪些更新与Ajax调用(jQuery的Ajax调用)页面上的局部视图视图页面上的搜索按钮。有这个局部视图更新调用返回局部视图单独行动。现在的问题是局部视图没有任何基础类和当显示在局部视图资源它们显示为默认培养而不是当前的文化。什么是设置CultureInfo的最佳方法时,部分观点是从jQuery的Ajax调用叫什么?

I have a viewpage and a partialview on that. For default request-when page is called- CultureInfo is set in base class of viewPage. I have created this custom base class which initialize the culture depending on a cookie and does some other stuff as well. There is a search button on the view page which updates a partial view on the page with Ajax call (jquery Ajax call). There is separate action for this partial view update call which returns partial view. The problem is partial view do not have any base class and when resources are displayed on partial view they are displayed for default culture and not the current culture. What would be best approach to set cultureInfo when partial view is called from jQuery Ajax call?

我有更大的现有应用程序的这个MVC应用程序的一部分(区),所以我不能碰在session_start。

I have this mvc application as part (area) of bigger existing application so I can not touch session_start.

推荐答案

我不知道为什么你需要通过周围的文化,你不能直接从PartialView使用一个辅助方法得到它?

I'm not sure why you need to pass the culture around, can't you get it directly from your PartialView using a helper method?

@YourApp.CultureHelper.GetCurrentCulture()

这是刚刚打电话

public static string GetCurrentCulture()
{
   return Thread.CurrentThread.CurrentCulture.Name;
}

如果你正在做的与国际化和ASP.NET MVC我强烈建议通过纳迪姆Afana这两个优秀的帖子读取任何工作

If you are doing any work with internationalization and ASP.NET MVC I highly recommend reading through these two excellent posts by Nadeem Afana

  • ASP.NET MVC 3 Internationalization
  • ASP.NET MVC 3 Internationalization - Part 2 (NerdDinner)

写得很好,解释了你需要了解的一切国际

Very well written and explains everything you need to know about internationalization.

这篇关于怎样的CultureInfo传递给partialView为Ajax调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆