0x800a139e - JavaScript运行时错误:在window.document对象上初始化工具提示时必须指定`selector`选项

时间:2016-08-03 18:14:37

标签: javascript c# asp.net asp.net-mvc

我正在尝试在索引视图中的工具提示中显示部分视图。当某人将鼠标悬停在软件标题上时,我希望工具提示出现。我的javascript代码位于_Layout页面的底部。

将鼠标悬停在软件标题上后,标签标题会在工具提示中加载,但是,它永远不会加载我的部分标题。

这实际上是两个问题:

  1. 为什么我会收到此问题标题中所述的错误?
  2. 为什么我的部分不会在工具提示中加载?
  3. 谢谢!

    此外,这与我的其他问题不同,因为我在javascript中出现了错误。我不确定我的包和布局参考是否按正确的顺序排列。

    捆绑配置:

    public class BundleConfig
    {
        // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));
    
            bundles.Add(new StyleBundle("~/bundles/jqueryui").Include(
                      "~/Scripts/jquery.ui-{version}.js"));
    
            //Create bundel for jQueryUI  
            //css  
            bundles.Add(new StyleBundle("~/Content/cssjqryUi").Include(
                   "~/Content/themes/base/jquery-ui.css"));
    
            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-{version}.js"));
    
            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/moment.js",
                      "~/Scripts/bootstrap-datetimepicker.js",
                      "~/Scripts/respond.js"));
    
            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/themes/base/datepicker.css",
                      "~/Content/site.css",
                      "~/Content/PagedList.css"));
    
    
    
        }
    
    }
    

    _Layout Page:

    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="x-ua-compatible" content="IE=Edge">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - GHSP Software License Manager</title>
    
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    
    @*<script src="~/Scripts/SoftwareDetails.js"></script>*@
    
    </head>
    
    <body>
    
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("Home", "Index", "Home", null, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("My Software", "UserSoftware", "SoftwareLicense")</li>
                    <li>@Html.ActionLink("My Contacts", "UserContact", "ContactInformation")</li>
                </ul>
                <p class="nav navbar-text navbar-right">Hello, @ViewBag.FullName!</p>
            </div>
        </div>
    </div>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <div class="content-wrapper">
                <div class="float-left">
                    @Html.Partial("_Footer")
                </div>
            </div>
        </footer>
    </div>
    
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryui")
    @Scripts.Render("~/bundles/bootstrap")
    
    @RenderSection("scripts", required: false)
    
    <script type="text/javascript">
    
        $(function () {
            var url = '@Url.RouteUrl(new{ action="SoftwareDetails", controller="SoftwareLicense"})';
            $(document).tooltip({
                items: "td.myToolTips",
                content: function (callback) {
                    $.get(url + "?id=" + $(this).data("id"))
                        .done(function (r) {
                            callback(r);
                        });
                }
            });
    
        });
    
    </script>
    
    </body>
    </html>
    

    索引视图:

    <table class="table">
        <tr>
            <th>
                @Html.ActionLink("Software Name", "Index", new { sortOrder = ViewBag.SoftNameSort, currentFilter = ViewBag.CurrentFilter })
            </th>
            <th>
                @Html.ActionLink("License Type", "Index", new { sortOrder = ViewBag.LicenseType, currentFilter = ViewBag.CurrentFilter })
            </th>
            <th>
                @Html.ActionLink("End Date", "Index", new { sortOrder = ViewBag.EndDateSort, currentFilter = ViewBag.CurrentFilter })
            </th>
            <th></th>
        </tr>
    
        @foreach (var item in Model)
        {
            <tr>
                <td class="myToolTips" id="@item.SoftwareID" title="Loading..">
                    @Html.DisplayFor(modelItem => item.SoftwareName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.LicenseType)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.EndDate)
                </td>
                <td>
                    @Html.ActionLink("Edit", "Edit", new { id = item.SoftwareID }) |
                    @Html.ActionLink("Details", "Details", new { id = item.SoftwareID }) |
                    @Html.ActionLink("Delete", "Delete", new { id = item.SoftwareID })
                </td>
            </tr>
            //count++;
        }
    </table>
    

    SoftwareDetails行动:

    public ActionResult SoftwareDetails(int id)
    {
        SoftwareLicense temp = db.SoftwareLicenses.Find(id);
        return Content("Tooltip for "+id);
    }
    

    SoftwareDetails Partial View:

    @model WBLA.Models.SoftwareLicense
    
    <table>
        <tr>
            <th>
                @Html.LabelFor(model => model.SoftwareName)
            </th>
            <td>
                @Html.DisplayFor(model => model.SoftwareName)
            </td>
        </tr>
        <tr>
            <th>
                @Html.LabelFor(model => model.SoftwareKey)
            </th>
            <td>
                @Html.DisplayFor(model => model.SoftwareKey)
            </td>
        </tr>
        <tr>
            <th>
                @Html.LabelFor(model => model.Price)
            </th>
            <td>
                @Html.DisplayFor(model => model.Price)
            </td>
        </tr>
        <tr>
            <th>
                @Html.LabelFor(model => model.DepartmentName)
            </th>
            <td>
                @Html.DisplayFor(model => model.DepartmentName)
            </td>
        </tr>
        <tr>
            <th>
                @Html.LabelFor(model => model.LicenseFilePath)
            </th>
            <td>
                @Html.DisplayFor(model => model.LicenseFilePath)
            </td>
        </tr>
        <tr>
            <th>
                @Html.LabelFor(model => model.LicenseType)
            </th>
            <td>
                @Html.DisplayFor(model => model.LicenseType)
            </td>
        </tr>
        <tr>
            <th>
                @Html.LabelFor(model => model.StartDate)
            </th>
            <td>
                @Html.DisplayFor(model => model.StartDate)
            </td>
        </tr>
        <tr>
            <th>
                @Html.LabelFor(model => model.EndDate)
            </th>
            <td>
                @Html.DisplayFor(model => model.EndDate)
            </td>
        </tr>
        <tr>
            <th>
                @Html.LabelFor(model => model.NotifyTime)
            </th>
            <td>
                @Html.DisplayFor(model => model.NotifyTime)
            </td>
        </tr>
        <tr>
            <th>
                @Html.LabelFor(model => model.ConsumerEmail)
            </th>
            <td>
                @Html.DisplayFor(model => model.ConsumerEmail)
            </td>
        </tr>
        <tr>
            <th>
                @Html.LabelFor(model => model.EntryEmail)
            </th>
            <td>
                @Html.DisplayFor(model => model.EntryEmail)
            </td>
        </tr>
    </table>
    

    注意:当我导航到_layout页面底部的javascript代码中所述的URL并在URL中提供id时,我的部分加载正常。所以我不相信这是我的部分观点的错误。

0 个答案:

没有答案