KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'd like to use string constants on both sides, in C# on server and in Javascript on client. I encapsulate my constants in C# class namespace MyModel { public static class Constants { public const string T_URL = "url"; public const string T_TEXT = "text"; . . . } } I found a way to use these constants in Javascript using Razor syntax, but it looks weird to me: @using MyModel <script type="text/javascript"> var T_URL = '@Constants.T_URL'; var T_TEXT = '@Constants.T_TEXT'; . . . var selValue = $('select#idTagType').val(); if (selValue == T_TEXT) { ... Is there any more "elegant" way of sharing constants between C# and Javascript? (Or at least more automatic, so I do not have to make changes in two files)
Tags (comma-separated)
Save Edits
Cancel