Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 4 如何在asp.net MVC4视图页面中包含javascript代码?_Asp.net Mvc 4 - Fatal编程技术网

Asp.net mvc 4 如何在asp.net MVC4视图页面中包含javascript代码?

Asp.net mvc 4 如何在asp.net MVC4视图页面中包含javascript代码?,asp.net-mvc-4,Asp.net Mvc 4,我是asp.NETMVC4体系结构的新手,我遇到以下问题,请帮助我 @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

我是asp.NETMVC4体系结构的新手,我遇到以下问题,请帮助我

@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>
@Scripts.Render(“~/bundles/jquery”)
@Scripts.Render(“~/bundles/jqueryui”)
$(函数(){
$(“#节”).tabs();
//这里我得到的错误是Object[Object]没有方法选项卡
});
第1节内容。。。。。。。。。。。。 第2节内容。。。。。。。。。。。。

提前感谢……

您可能已经包含了两次
~/bundles/jquery
捆绑包。签出您的
~/Views/Shared/_Layout.cshtml
文件。最后,您可能有以下几点:

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

更新:

下面是视图结构的完整示例:

@{
    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>
@{
布局=空;
}
福
第1节内容。。。。。。。。。。。。 第2节内容。。。。。。。。。。。。 @Scripts.Render(“~/bundles/jquery”) @Scripts.Render(“~/bundles/jqueryui”) $(“#节”).tabs();
谢谢您的回复…但是当我删除@Scripts.Render(“~/bundles/jqueryui”)这一行时,它说$未定义…您不应该删除
@Scripts.Render(“~/bundles/jqueryui”)
这一行。如果
\u Layout.cshtml
中已经存在
@Scripts.Render(“~/bundles/jquery”)
行,则应删除该行。是这样吗?我已经用一个例子更新了我的答案,说明了您的视图可能是什么样子。当您不使用bundler时,您是如何做到这一点的?(或任何其他缩略)我得到了与OP相同的行为。它包含在_布局中,但是我还必须将它包含在我想要使用JavaScript的每个页面中。否则我将得到未定义的$。
@{
    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>