Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • ThomasBrunbjerg 89 posts 181 karma points
    Sep 07, 2017 @ 06:41

    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:

            displayWeekNumber: true,
            customDayRenderer: function (element, date) {
                $(element).css('background-color', 'red');
                $(element).css('color', 'white');
                $(element).css('border-radius', '15px');

    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?

  • Aristotelis Pitaridis 82 posts 400 karma points
    Sep 07, 2017 @ 07:43
    Aristotelis Pitaridis

    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):

    @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

    Kind Regards,


  • Laurent Lequenne 121 posts 246 karma points
    Sep 07, 2017 @ 07:43
    Laurent Lequenne

    Have a look on how to work with Razor and sections :-)

Please Sign in or register to post replies

Write your reply to: