This is what I have done;
Firstly, I have all my scripts that I will ever need in one external JS file.
In my MVC layout page I have created the div for the data-role wrapper to set its id attribute from a property each and every controller action will return with a unique value.
The layout page.
<body class="ui-mobile-viewport">
<div data-role="page" id="@ViewBag.PageId">
Then in my Controller Action I return a unique value to the view;
public ActionResult Index()
{
ViewBag.PageId = "pageCustomers";
return View();
}
This means that I can bind to the page.init event as follows. The script below is wrapped in <script>
tags in the in the MVC view that the controller returns and allows custom JS code for that particular view to be fired when the view has loaded.
$('#pageCustomers').live('pageinit', function (event) {
// do something
}