I tried to place a script in a specified portion of a layout using @section inside a partial view. But it is not working.
_Layout.cshtml
<!DOCTYPE html>
<html lang="en">
<head>
@RenderSection("PageSpecificCSSFiles", false)
</head>
<body>
<div>@RenderBody()</div>
<script src="@Url.Content("~/Scripts/jquery-1.8.2.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery-ui.js")"></script>
@RenderSection("PageSpecificJSFiles", false)
@RenderSection("PageSpecificJSScript", false)
</body>
DetailPage.cshtml
@{
ViewBag.Title = "Details";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div id="tabs">
@{ Html.RenderPartial("BasicDetails");}
</div>
Partial View BasicDetails.cshtml
<input id="dob" name="DateOfBirth" value="" />
@section PageSpecificJSScript{
<script type="text/javascript">
$(document).ready(function(){
$('#dob').datepicker();
});
</script>
}
The datepicker has not configured because @section is not working.
Could any one tell how to achieve this in partial view? How can we force a script inside a partial views into a particular portion of a layout?
Note: I have added JS files at bottom in order to improve performance. I don't prefer moving it to top of the page.