javascript - Using MVC resource in Jquery - function stops working -


i have jquery function in mvc view check if @ least 1 checkbox clicked. function working if use hardcoded string. when add @resources.mystring into, stops working, can't figure out why

    $('.form-horizontal').on('submit', function (e) {         if ($("input[type=checkbox]:checked").length === 0) {             e.preventdefault();              alert("this working");             alert(@resources.mystring); //with function not working anymore              return false;         }     }); 

i need add the string multilingual purpose. tried diferent aproches

alert(@resources.mystring); alert(@html.raw(resources.mystring)) var aaa = { @html.raw(resources.mystring)} //and calling aaa 

i think missing basic knowlage of how should work together

during page rendering, @resources.mystring injected in code. instance, if mystring == "abc";, you'll end alert(abc); not want.

just try enclose string in quotes:

alert("@resources.mystring"); 

as aside, putting razor code in javascript logic considered bad practice, prevents putting javascript code in separate files (and therefore caching), , makes code less readable.

take this question , provided answer gives simple way deal that.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -