0

I am working on a mvc application, there is a label for e.g. called "The count is 12 apples". Now I have to put the label in resource file, but the problem is that the no. 12 is dynamic and changes on selection of some other drop down using jquery.

The html code is:

<p>The count is <span>12</span> apples</p>

I can not have hard coded text in my app, hence need to put both "The count is" & "apples" in resource file, so my doubt is that do I need to have 2 values in resource file for this OR is there any other way I can tackle this problem i.e. avoid having 2 in resource file considering there is count in between which is dynamic.

whyAto8
  • 1,660
  • 4
  • 30
  • 56

1 Answers1

1

You can set the resource string to something like "The count is {0} apples". You can then assign the value to place into {0} in the code behind.

Eg.

string count = string.format(Resource.AppleCount, 12);

12 will replace the {0} giving "The count is 12 apples"

If you want to maintain the <span> element, you do the same thing, but your resource string will be The count is <span>{0}</span> apples and use .innerHTML to insert it

I haven't worked directly with MVC, but I think this will solve your problem

Adam Botley
  • 672
  • 7
  • 14
  • I just have to make changes in html file/resource file/js file, not code behind. So, will this still work? – whyAto8 Oct 14 '13 at 13:27