Skip to content

Instantly share code, notes, and snippets.

@JasonMore
Created August 12, 2011 14:29
Show Gist options
  • Save JasonMore/1142146 to your computer and use it in GitHub Desktop.
Save JasonMore/1142146 to your computer and use it in GitHub Desktop.
Seperating JS from the view
@*http://www.telerik.com/help/aspnet-mvc/web-assets-working-with-javascript-web-assets.html*@
@{
Html.Telerik().ScriptRegistrar()
.Scripts(script => script
.Add("Calldirector.application.js")
)
.OnDocumentReady(@<text>
CallDirector_application.selectedMenuActionId('@(Url.Action("foo"))');
</text>);
}
//javascript namespacing
//start class
var CallDirector_application = {};
(function () {
//private members
var $selectedMenuAction;
//public memeber
this.selectedMenuActionId = function (id) {
$selectedMenuAction = $('#' + id);
}
//end class
}).apply(CallDirector_application);
<script src="../../Scripts/Calldirector.application.js" />
<script type="text/javascript">
//document onload
$(function () {
CallDirector_application.selectedMenuAction('@(Url.Action("foo"))');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment