In the MVC application I'm developing, all JavaScript for the pages is stored in separate JavaScript files without any script tags on the pages. There's a Messages class containing Errors, Information, and Confirmation classes with static strings. While error and information messages are fetched from the server, confirmation messages like "Do you wish to Save (OK/Cancel)" are hardcoded in each JavaScript file. I now want the JavaScript code to utilize the confirmation messages from the Messages.Confirmation class.
To address this issue, I currently implement the following solution on my page:
<%@ Import Namespace="Business.Common" %>
.....
<script type="text/javascript">
confirmSaveQuestion = '<%= Messages.Confirmations.CONFIRM_SAVE %>';
</script>
Meanwhile, my .js file is structured as follows:
var confirmSaveQuestion;
function ConfirmSave() {
var result = window.confirm(confirmSaveQuestion);
if (result)
return true;
else
return false;
}
This setup works effectively, but I'm curious about the possibility of importing the Business.Common namespace into the .js file directly. This way, I wouldn't need to define the value for confirmSaveQuestion on my page.