1

I'm developing a app in .net mvc and I am using the concept of Localisation by having a separate .resx file for flexibility of being able to organize the strings quickly and efficiently. And in the process, I'm having e few javascript code, that has some alerts and confirm boxes being displayed on certain actions. I do not have a separate .js file but just had embedded the code into the .cshtml file. My question is, Cant i take these alert and confirm messages from the .resx file as well?.. I have alreday browsed a lot and no fruitful result of how to use the .resx string within the javascript code? i tried something like,

              <script type="javascript">
              var confirm_text= @ResourceLocalisation.ConfirmText
              var confirmText=confirm(confirm_text);
              if(confirmText==true)
              .....

But this dint work.. What am I missing?.. Can Someone help me achieve localistion for javascript code?.. My question may be a dupe of, How to get texts from Resx to be used in Javascript?? but I'm posting this only because I dint get my question answered in this post..

Is there some configuration that i should be doing in web.config file aswell ?..

Thanks in Advance..;)

1 Answer 1

1

We do that all the time, and it works properly for us. Can you show a copy of the HTML generated? Also, the text should be quoted.

@model MyModel
@using My.App.ResourcesProject  // if needed

<script type="text/javascript">
    var str = "@LocalizedStrings.AlertText";
    alert(str);
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.