locked
<script> tag giving error in layout page ASP.NET Core 2.2 RRS feed

  • Question

  • User-973886032 posted

    Hi guys

    I am trying to migrate a project from core 2.0 to core 2.2 and added the <script> opening and closing tags with the document.ready function

    to the bottom of my layout page and I get this error

     Severity Code Description Project File Line Suppression State Error RZ1034 Found a malformed 'body' tag helper. Tag helpers must have a start and end tag or be self closing. xad C:\Users\ehioz\OneDrive\Documents\MEGAsync\IT Projects\Xa\Views\Shared\_Layout.cshtml 21

     <footer class="border-top footer text-muted">
            <div class="container">
                &copy; 2019 - xad- <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
            </div>
        </footer>
    
        <environment include="Development">
            <script src="~/lib/jquery/dist/jquery.js"></script>
            <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.js"></script>
        </environment>
        <environment exclude="Development">
            <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"
                    asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
                    asp-fallback-test="window.jQuery"
                    crossorigin="anonymous"
                    integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=">
            </script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.bundle.min.js"
                    asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"
                    asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
                    crossorigin="anonymous"
                    integrity="sha256-E/V4cWE4qvAeO5MOhjtGtqDzPndRO1LBk8lJ/PR7CA4=">
            </script>
        </environment>
        <script src="~/js/site.js" asp-append-version="true"></script>
    
        @RenderSection("Scripts", required: false)
    
    
    
          <script>
            $(document).ready(function () {
    
    
    

    unlike my VS 2017 and asp.net 2.0 version the colours changes, however in VS2019 and asp.net core 2.2 the colour does not change

    what is wrong here and was the inserting of javascript changed ?

    thanks

    Ehi

    Friday, June 21, 2019 12:15 PM

All replies

  • User475983607 posted

    The code snippet posted is missing the closing tag and closing brackets.

    I added the following to my _layout page in an ASP.NET Core  2.2 and the code write "Hello World" to the console as expected.

        @RenderSection("Scripts", required: false)
        <script>
            $(document).ready(function () {
                console.log("Hello World!");
            });
        </script>
    
    </body>
    </html>

    The error message states you have a malformed body tag.  You code is incomplete so we can very well provide a solution.  Maybe you accidentally deleted the ending </body> tag?

    Friday, June 21, 2019 12:34 PM
  • User-973886032 posted

    The code snippet posted is missing the closing tag and closing brackets.

    I added the following to my _layout page in an ASP.NET Core  2.2 and the code write "Hello World" to the console as expected.

        @RenderSection("Scripts", required: false)
        <script>
            $(document).ready(function () {
                console.log("Hello World!");
            });
        </script>
    
    </body>
    </html>

    The error message states you have a malformed body tag.  You code is incomplete so we can very well provide a solution.  Maybe you accidentally deleted the ending </body> tag?

    apologies, I should have pasted my entire code, the closing tags and brackets were present. It still gives the same error

    Friday, June 21, 2019 1:09 PM
  • User-973886032 posted

    The code snippet posted is missing the closing tag and closing brackets.

    I added the following to my _layout page in an ASP.NET Core  2.2 and the code write "Hello World" to the console as expected.

        @RenderSection("Scripts", required: false)
        <script>
            $(document).ready(function () {
                console.log("Hello World!");
            });
        </script>
    
    </body>
    </html>

    The error message states you have a malformed body tag.  You code is incomplete so we can very well provide a solution.  Maybe you accidentally deleted the ending </body> tag?

    sorry I found the problem, I was using </scripts> to close it instead of </script>

    its working now, many thanks

    Friday, June 21, 2019 1:41 PM