I'm lost with so many examples and solutions out here I cannot seem to find anything that makes sense to me. So, I'm going to take a baby step and ask How do you move JavaScript file reference from existing view (that will now be a Partial view) to Main view?
Existing Report View
This will become my partial view, so I cannot use the @Scripts.Render("~/bundles/App/UsageReport") anymore. Once this is rendered as a partial page I must include this JavaScript file in the Main page.
@{
ViewBag.Title = "Usage Report";
}
<main id="usageData">
.
.
.
<div id="loading">
</div>
</main>
@section scripts{
@Scripts.Render("~/bundles/App/UsageReport")
<script type="text/javascript">
$(function () { UsageReport.initModule() });
</script>
}
Main View
Where / How do I include UsageReport.js in the Main view shown below?
@{
ViewBag.Title = "Main View";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<main id="mainView">
.
.
.
<div id="loading">
</div>
</main>
@section scripts{
@Scripts.Render("~/bundles/App/MainView")
<script type="text/javascript">
$(function () { MainView.initModule('@ViewBag.Name') });
</script>
}
I'll include any other code you need but I'm not sure what is important to add for this dumbass question.
Scripts.Render("~/bundles/App/UsageReport")in the@section scripts{of your main view. It not clear whatUsageReport.initModule()does, but if the partial is loaded dynamically, you would need to call that in the success call back of the ajax call