English 中文(简体)
在 MVC 视图中显示变量文本
原标题:Showing variable text in MVC View

我为下列问题寻找一个好的解决办法:

我有一个ASP.NET MVC Web应用程序,供我的几个客户使用。在这个应用程序中,客户可以登录、浏览多页信息并填写若干表格。这一切都很有效。

然而,我要的是,视客户的属性而定,在观点中显示不同的文本(在本案中是一类),这些文本可以是多种语言的,用户可以改变申请中的语言。

我为此提出了几种解决办法,但我不知道什么是最好的办法。

< 坚固 > 保存数据库中的信息

在此情况下, 我将创建一个表格( 如程序文本 ), 包含一个 Key 、 客户类型、 语言和文本 。 在我的主计长中, 我将检索此视图中使用的密钥, 将其设置在视图模式中, 并将该视图模型传送到视图中 。 在视图模式中, 我就可以轻松显示给定变量的价值 。

我认为这对一个小的站点效果很好,但似乎对许多不同的控制器和观点有点粗糙。 我宁愿直接从视图中调用文本,但从视图中拨打数据库的电话并没有好得多。

<强度> 资源文件

我的另一个想法是使用资源文件, 因为本地化特性的构建 。 我不知道如何从资源中获取变量, 以额外变量为基础( 本案中的类型) 。

是否有人知道如何实现这一目标?

最佳回答

我将选择资源文件选项。 是否有可能为不同类型拥有不同的资源文件? 还是有可能为不同类型拥有不同的变量名称?

eg eg

Message1_TypeA
Message2_TypeB

等等

然后,你可以使用一些聪明的把戏 读取正确的信息 取决于类型, 一个聪明的把戏,比如反省。

另一种选择可能是因此划定字符串的界限

消息1 = "ABCD";

这样您就可以获取所有类型的信息, 然后在代码中您可以获取当前类型的正确信息。 我解释得清楚吗? 我不认为我做到了 。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签