我在文件末尾有以下 Asp.Net MVC 4 剃须刀代码。
....
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
<script type="text/javascript">
$('#Address_State').val('MA');
</script>
////// End of file
但是,它生成了以下 html 代码。它会在该行引发错误$('#Address_State').val('MA');
。错误消息是Uncaught ReferenceError: $ is not defined
。如何在剃刀文件中插入 jQuery 代码?
.....
<script type="text/javascript">
$('#Address_State').val('MA'); // Uncaught ReferenceError: $ is not defined
</script>
</section>
</div>
<footer>
<div class="content-wrapper">
<div class="float-left">
<p>© 2013 - Paperspeed</p>
</div>
</div>
</footer>
<script src="/Scripts/jquery-1.9.1.js"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
</body>
</html>
更新:
以下是_Layout.cshtml 的最后四行。
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body>
</html>