Im having problem with the scripts on the layout, so I go to the basic to try understand what is doing the @RenderSection("scripts",
and now I make it work.
But can I put the Jquery / Jquery.UI (js/css) in the Layout, so I dont have to put it on every view? because I try puting inside the head tag on the Layout and the view didnt saw it.
Here is my layout.
<html>
<head>
<title>@ViewBag.Title</title>
</head>
<body>
<h1>Test Layout</h1>
<div>
@RenderBody()
</div>
</body>
</html>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
And my View
@{
ViewBag.Title = "TreeDetails";
Layout = "~/Views/Shared/_LayoutTest.cshtml";
}
<html>
<head>
<title>@ViewBag.Title</title>
</head>
<body>
<h2>TEST PAGE</h2>
<div id="dialog" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
<button id="opener">Open Dialog</button>
</body>
</html>
@section scripts {
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
// Your code goes here.
$(document).ready(function () {
console.log("before dialog");
$("#dialog").dialog({ autoOpen: false });
console.log("after dialog");
$("#opener").click(function () {
$("#dialog").dialog("open");
});
})
</script>
}
` tag. Note also that your css file should be in a separate `@RenderSection("styles", required: false)` inside the `
` tags. And it also looks like your repeating `jquery.js`using `@Scripts.Render("~/bundles/jquery")` in the layout and again by including it inside `@section scripts {`
– Jun 21 '16 at 01:37