【问题标题】:I can't use JQueryUI with ASP.NET MVC4我不能将 JQueryUI 与 ASP.NET MVC4 一起使用
【发布时间】:2013-12-10 22:51:15
【问题描述】:

我想在我的 MVC4 应用程序中使用 JQueryUI,但我没有看到我想要的效果。 我将向您展示代码,我认为这是初学者的错误。我一定忘记了一个指令。

_Layout.cshtml(只是声明)

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8" />
<title>@ViewBag.Title - Mon application ASP.NET MVC</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@RenderSection("JavaScript", required: false)
@Styles.Render("~/Content/css")

myView.cshtml

@section JavaScript
{
<script type="text/javascript">
    $(function () {
        $("#dialog").dialog({
            autoOpen: false,
            show: {
                effect: "blind",
                duration: 1000
            },
            hide: {
                effect: "explode",
                duration: 1000
            }
        });

        $("#opener").click(function () {
            $("#dialog").dialog("open");
        });
    });
</script>
}
@{
    ViewBag.Title = "Home Page";
}
@{
    if (!Session.IsNewSession && Session.Contents["connecte"].Equals(true))
    {
        <div id="dialog" title="Basic dialog">
            <p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
        </div> 
        <button id="opener">Open Dialog</button>  
    }
    else
    {
     <div class="group_bannner_right">
        <img src="~/Images/picture.png" width="550" height="316" alt="baner">
    </div>

    <header class="group_bannner_left">
        <hgroup>
            <h1>Simple.Think. </h1>
            <h2>
                “The little things are infinitely the most important.“
            </h2>
        </hgroup>
    </header> 
    }   
}

我有这个错误:

Uncaught TypeError: Object [object Object] has no method 'dialog' 
(index):18 (anonymous function) 
(index):18 fire 
jquery-1.8.2.js:988 self.fireWith 
jquery-1.8.2.js:1096 jQuery.extend.ready 
jquery-1.8.2.js:420 DOMContentLoaded

【问题讨论】:

  • 看起来不错,您是在编辑 Bundler 文件后构建的吗?和/或检查控制台错误是什么/是否有任何错误。
  • 我没有编辑 Bundler 文件。
  • 我只想这样做JQueryUI
  • 检查浏览器开发工具中的 javascript 控制台和网络选项卡是否有错误。
  • 我有这个与我的案例有关的错误:未捕获的 TypeError: Object [object Object] has no method 'dialog' (index):18 (anonymous function) (index):18 fire jquery-1.8 .2.js:988 self.fireWith jquery-1.8.2.js:1096 jQuery.extend.ready jquery-1.8.2.js:420 DOMContentLoaded

标签: jquery asp.net jquery-ui asp.net-mvc-4


【解决方案1】:

jQueryUI 未加载,按 CTRL + SHIFT + F,在整个解决方案中搜索“~/bundles/jqueryui”。您将在 BundleConfig.cs 中看到匹配项,您会发现文件路径与 jQuery 在您网站中的位置不正确。

如果您手动重新组织了您的 jQuery UI 文件,可能会导致这种情况。

在 BundleConfig.cs 中编辑 jQueryUI 的文件路径,使其正确,确保在更改 BundleConfig.cs 后构建您的项目。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-11
    • 1970-01-01
    相关资源
    最近更新 更多