MVC 4 - multi DisplayName in Model

119 views Asked by At

Hy, I have the problem that I am programing a site for multi businesses. I use DisplayName and LabelFor. The site is similar for each business, only the LabelFor name changes. I found a lot of multi-language possibilities using resource files (resx) and culture. But I don’t want to use this because it’s not a culture “problem”. So the question is…

  1. Can I use resx files without using culture? Maybe control with some other global parameter
  2. Can I get the string from database using “Stringkey” and business “id” (eg: Search.Label.Firstname,
  3. Is there any other possibility/idea to do this?

Thx a lot Chris

1

There are 1 answers

0
NightOwl888 On

Here are a couple of options:

  1. Create a custom HTML helper (perhaps just an overload of LabelFor) to pull your label from client-based resource files. Name each resource file after the business it applies. You could easily read some global state from an HTML helper. You also still have the option to localize the labels for each business.
  2. Rather than using LabelFor, make the label text part of your view model. You would then have many options where to retrieve it from.

public class MyModel
{
    public string NameLabel { get; set; }
    public string Name { get; set; }
}