如何纳入asp.net MVC4 View页面的JavaScript code? [英] How to include javascript code in asp.net MVC4 View page?

查看:116
本文介绍了如何纳入asp.net MVC4 View页面的JavaScript code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来asp.net MVC4建筑我是卡住具有如下的东西请帮助我。

i am new to asp.net MVC4 architecture i am get stuck with following thing please help me.

@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>

在此先感谢......

THANKS IN ADVANCE......

推荐答案

您可能已经包含在〜/包/ jQuery的捆绑的两倍。结帐你的〜/查看/共享/ _Layout.cshtml 文件。在最后你可能有以下几点:

You probably have included the ~/bundles/jquery bundle twice. Checkout your ~/Views/Shared/_Layout.cshtml file. At the end you probably have the following:

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

所以jQuery的包已经包含在你的页面。你不应该将它包括在视图内的第二次。你只需要在〜/包/ 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>


更新:

下面是你的视图的结构如何可能看起来像一个完整的例子:

Here's a full example of how the structure of your view might look like:

@{
    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 MVC4 View页面的JavaScript code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆