gpt4 book ai didi

asp.net-mvc-4 - 如何在asp.net MVC4 View 页面中包含javascript 代码?

转载 作者:行者123 更新时间:2023-12-04 06:27:38 25 4
gpt4 key购买 nike

我是 ASP.NET MVC4 架构的新手,我遇到了以下问题,请帮助我。

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")

<script type="text/javascript">
$(function () {
$("#sections").tabs();
//here i am getting error that Object[object object] has not method tabs
});
</script>

<div id="sections">
<ul>
<li><a href="#section-1">section-1 </a></li>
<li><a href="#section-2">section-2 </a></li>
</ul>
<div id="section-1">
section-1 content............
</div>
<div id="section-2">
section-2 content............
</div>
</div>

提前致谢......

最佳答案

您可能已经包含了 ~/bundles/jquery捆绑两次。结帐您的 ~/Views/Shared/_Layout.cshtml文件。最后你可能有以下内容:

    @Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body>

因此 jQuery 包已经包含在您的页面中。您不应在 View 中再次包含它。您只需要 ~/bundles/jqueryui捆:
@Scripts.Render("~/bundles/jqueryui")

<script type="text/javascript">
$(function () {
$("#sections").tabs();
//here i am getting error that Object[object object] has not method tabs
});
</script>

<div id="sections">
<ul>
<li><a href="#section-1">section-1 </a></li>
<li><a href="#section-2">section-2 </a></li>
</ul>
<div id="section-1">
section-1 content............
</div>
<div id="section-2">
section-2 content............
</div>
</div>

更新:

这是 View 结构的完整示例:
@{
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Foo</title>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />
</head>
<body>
<div id="sections">
<ul>
<li><a href="#section-1">section-1 </a></li>
<li><a href="#section-2">section-2 </a></li>
</ul>
<div id="section-1">
section-1 content............
</div>
<div id="section-2">
section-2 content............
</div>
</div>

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
<script type="text/javascript">
$("#sections").tabs();
</script>
</body>
</html>

关于asp.net-mvc-4 - 如何在asp.net MVC4 View 页面中包含javascript 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12932544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com