I have a pretty standard MVC solution with _Layout.cshtml, Index.cshtml, etc. I'm trying to load some required bundles in the Layout only one time, so that when I change views, I only get what I need from the server, not what I already have (bundles, layout html, etc).
Following this post: MVC 3: How to render a view without its layout page when loaded via ajax?
I now have an updated _ViewStart. It doesn't seem to be working though:
With the following JS viewmodel being loaded as part of the bundle in _Layout:
var subjectservice = new baseservice(); // baseservice is an empty function
subjectservice.subjects = {};
subjectservice.getSubjects = function () {
alert('Hit');
subjectservice.subjects = 'data';
}
subjectservice.getSubjects();
The intended behavior is that:
- I get Subjects when I initially load the application (with _Layout), no matter what page I'm on
- I don't call getSubjects again when navigating - only when I specifically call it from other viewmodels
However, no matter what page I navigate to, I always get the alert message, even if Layout has already loaded. Viewing the network panel in Chrome Debugger shows all of my bundled js files are getting reloaded with every page load.
An example of a view that I'm trying to load without re-loading bundles and _Layout:
public ActionResult Index()
{
return View();
}
How can I load Layout and its bundles only once?