javascript alert not firing in layout.cshtml

websss
websss used Ask the Experts™
on
I have a layout.cshtml page

I'm trying to get a simple alert('hi'); to fire, but none of the alerts below are firing

 @section scripts{
        <script type="text/javascript">
               alert('hi');
            $(document).ready(function () {

                alert('layout');
               
            });

        </script>
    }

  @RenderBody()


    <!-- PAGE FOOTER -->
    <div class="page-footer">
        <div class="row">
            <div class="col-xs-12 col-sm-6">
                <span class="txt-color-white">@ViewBag.Footer</span>
            </div>

        </div>
    </div>


  @RenderSection("scripts", required: false)

Open in new window



Is there some special order i have to follow to get this working?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
PANkaj KumarSoftware Developer
Commented:
Can not use @section scripts and @RenderSection("scripts", required: false) in same page.
Senior Software Engineer
Top Expert 2009
Commented:
AS posted previously do not use section script in the layout code. Section script is used on the other pages that use your layout so that all scripts appear in just one place  of your page. Typically they are added at the end of your body element page. For example:
 <body>
	@RenderBody()
    <!-- PAGE FOOTER -->
    <div class="page-footer">
        <div class="row">
            <div class="col-xs-12 col-sm-6">
                <span class="txt-color-white">@ViewBag.Footer</span>
            </div>

        </div>
    </div>
	
	<!-- Scrips go here, easy to spot and troubleshoot when debugging in browser -->
	<script type="text/javascript">
		   alert('hi');
		$(document).ready(function () {

			alert('layout');
		   
		});

	</script>
	@RenderSection("scripts", required: false) 
 </body>

Open in new window

websssCEO

Author

Commented:
thanks both, got it working

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial