I have a child template in my MVC project where I want to initialize a Javascript framework. This should not be done on the master template, as I need some razor code on the page to work with the framework. The framework in question is Bootstrap-Year-Calendar, which I need to have talk to an SQL Database. Each child template will receive different data, so I cannot put the code on the master template for this. But if a place a script tag on the child template with the code to initialize the framework:
But when I put the script tag with the code on my child template I receive this error:
TypeError: $(...).calendar is not a function
I have the .js and .css files included n my master template, so they should be available to use on the child template. My project was made with Umraco CMS as well.
How can I display the calendar on my child templates?
Your problem is that in your final html the jQuery code is before your jQuery librari definition. In your master template type the following line at the location you want the script to be placed (after your jquery definition):
@RenderSection("scripts", required: false)
In you child template type the following code:
@section scripts{
<script type="text/javascript">
$(function () {
// Here you can place your jquery
});
</script>
}
Adding script tags on child templates
I have a child template in my MVC project where I want to initialize a Javascript framework. This should not be done on the master template, as I need some razor code on the page to work with the framework. The framework in question is Bootstrap-Year-Calendar, which I need to have talk to an SQL Database. Each child template will receive different data, so I cannot put the code on the master template for this. But if a place a script tag on the child template with the code to initialize the framework:
But when I put the script tag with the code on my child template I receive this error:
I have the .js and .css files included n my master template, so they should be available to use on the child template. My project was made with Umraco CMS as well.
How can I display the calendar on my child templates?
Hello Thomas,
Your problem is that in your final html the jQuery code is before your jQuery librari definition. In your master template type the following line at the location you want the script to be placed (after your jquery definition):
In you child template type the following code:
Kind Regards,
Aristotelis
Have a look on how to work with Razor and sections :-)
is working on a reply...