我在布局页面中添加了jquery脚本。但在子视图中无法访问它。我没有使用任何捆绑。
Layout.cshtml
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title </title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>Test Apppp</h1>
@RenderBody()
<script src="/Scripts/modernizr-2.7.2.js"></script>
<script src="/Scripts/jquery.min.js"></script>
<script src="/Scripts/bootstrap.min.js"></script>
</body>
</html>
MyView.cshtml
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div style="width: 100%; height: 500px;" class="float_left">
</div>
<script type="text/javascript">
$(document).ready(function () {
alert('dd');
});
</script>
错误显示在$(文档).ready(function){})中;像$没有定义 请建议解决方案
提前致谢
答案 0 :(得分:2)
使用@RenderBody()
并在scripts
RenderBody()
<script src="/Scripts/modernizr-2.7.2.js"></script>
<script src="/Scripts/jquery.min.js"></script>
<script src="/Scripts/bootstrap.min.js"></script>
@RenderBody()
答案 1 :(得分:0)
Layout.cshtml
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title </title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="~/Scripts/modernizr-2.7.2.js"></script>
<script src="~/Scripts/jquery.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
</head>
<body>
@RenderBody()
</body>
</html>
MyView.cshtml
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript" language="javascript">
$(document).ready(function () {
alert('dd');
});
</script>
<div style="width: 100%; height: 500px;" class="float_left">
</div>