1

エラー:0x800a138f-Microsoft JScriptランタイムエラー:プロパティ'unobtrusive'の値を取得できません:オブジェクトがnullまたは未定義です

ここの下部にリストされているIndex.cshtmlは、私の問題が発生する場所です。

BundleConfig.cs:

using System.Web;
using System.Web.Optimization;

namespace MyWebMVC
{
   public class BundleConfig
   {
      public static void RegisterBundles(BundleCollection bundles)
      {
          bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                      "~/Scripts/jquery-{version}.js"));

          bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
                      "~/Scripts/jquery-ui-{version}.js"));

          bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                      "~/Scripts/jquery.validate*",
                      "~/Scripts/jquery.unobtrusive*"
                      ));

          bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                      "~/Scripts/modernizr-*"));

          bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/site.css"));

          bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
                      "~/Content/themes/base/jquery.ui.core.css",
                      "~/Content/themes/base/jquery.ui.resizable.css",
                      "~/Content/themes/base/jquery.ui.selectable.css",
                      "~/Content/themes/base/jquery.ui.accordion.css",
                      "~/Content/themes/base/jquery.ui.autocomplete.css",
                      "~/Content/themes/base/jquery.ui.button.css",
                      "~/Content/themes/base/jquery.ui.dialog.css",
                      "~/Content/themes/base/jquery.ui.slider.css",
                      "~/Content/themes/base/jquery.ui.tabs.css",
                      "~/Content/themes/base/jquery.ui.datepicker.css",
                      "~/Content/themes/base/jquery.ui.progressbar.css",
                      "~/Content/themes/base/jquery.ui.theme.css"));
      }
   }
}

_rootLayout.cshtml:

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8" />
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <meta name="viewport" content="width=device-width" />
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

    <link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" />
    <script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Scripts/js")" type="text/javascript"></script>

@Html.DevExpress().GetStyleSheets( 
    new StyleSheet { ExtensionSuite = ExtensionSuite.NavigationAndLayout }, 
    new StyleSheet { ExtensionSuite = ExtensionSuite.Editors }, 
    new StyleSheet { ExtensionSuite = ExtensionSuite.HtmlEditor }, 
    new StyleSheet { ExtensionSuite = ExtensionSuite.GridView }, 
    new StyleSheet { ExtensionSuite = ExtensionSuite.PivotGrid },
    new StyleSheet { ExtensionSuite = ExtensionSuite.Chart },
    new StyleSheet { ExtensionSuite = ExtensionSuite.Report },
    new StyleSheet { ExtensionSuite = ExtensionSuite.Scheduler }
)
@Html.DevExpress().GetScripts( 
    new Script { ExtensionSuite = ExtensionSuite.NavigationAndLayout }, 
    new Script { ExtensionSuite = ExtensionSuite.HtmlEditor }, 
    new Script { ExtensionSuite = ExtensionSuite.GridView }, 
    new Script { ExtensionSuite = ExtensionSuite.PivotGrid },
    new Script { ExtensionSuite = ExtensionSuite.Editors }, 
    new Script { ExtensionSuite = ExtensionSuite.Chart },
    new Script { ExtensionSuite = ExtensionSuite.Report },
    new Script { ExtensionSuite = ExtensionSuite.Scheduler }
)
</head>
<body>
    @Html.DevExpress().Splitter(settings => {
        settings.Name = "MainSplitter";
        settings.AllowResize = false;
        settings.Orientation = System.Web.UI.WebControls.Orientation.Vertical;
        settings.FullscreenMode = true;
        settings.SeparatorVisible = false;
        settings.Styles.Pane.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
        settings.Styles.Pane.Paddings.Padding =    System.Web.UI.WebControls.Unit.Pixel(0);

    settings.Panes.Add(pane => {
        pane.Name = "Header";
        //pane.ScrollBars = System.Web.UI.WebControls.ScrollBars.Auto;
        pane.Size = System.Web.UI.WebControls.Unit.Pixel(140);
        pane.MinSize = System.Web.UI.WebControls.Unit.Pixel(83);
        pane.PaneStyle.BorderBottom.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
        pane.PaneStyle.CssClass = "headerPane";
        pane.SetContent(() => {
            Html.RenderPartial("HeaderPartialView");
        });
    });

    settings.Panes.Add(pane => {
        pane.Name = "Content";
        pane.PaneStyle.CssClass = "mainContentPane";
        pane.MinSize = System.Web.UI.WebControls.Unit.Pixel(375);
        pane.PaneStyle.BackColor = System.Drawing.Color.White;
        pane.PaneStyle.BorderBottom.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
        pane.SetContent(RenderBody().ToHtmlString());
        pane.ScrollBars = System.Web.UI.WebControls.ScrollBars.Auto;
    });

    settings.Panes.Add(pane => {
        pane.Name = "Footer";
        pane.Size = System.Web.UI.WebControls.Unit.Pixel(25);
        pane.PaneStyle.CssClass = "footerPane";
        pane.SetContent(() => {
            Html.RenderPartial("FooterPartialView");
        });
    });

    Scripts.Render("~/bundles/jqueryval");
    Scripts.Render("~/bundles/jquery"); 
}).GetHtml()
</body>
</html>

_mainLayout.cshtml:

@{ Layout = "~/Views/Shared/_rootLayout.cshtml"; }

@Html.DevExpress().Splitter(settings => {
    settings.Name = "ContentSplitter";
    settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
    settings.Height = System.Web.UI.WebControls.Unit.Percentage(100);
    settings.Styles.Pane.Paddings.Padding = System.Web.UI.WebControls.Unit.Pixel(0);
    settings.Styles.Pane.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
    settings.Panes.Add(subpane => {
        subpane.Name = "ContentCenter";
        subpane.PaneStyle.CssClass = "contentPane";
        subpane.Separator.Visible = DevExpress.Utils.DefaultBoolean.True;
        subpane.ScrollBars = System.Web.UI.WebControls.ScrollBars.Auto;       
        subpane.Separator.SeparatorStyle.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
        subpane.Separator.SeparatorStyle.BorderTop.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
        subpane.SetContent(RenderBody().ToHtmlString());
    });

}).GetHtml()

Index.cshtml :(これは私のスクリプトがエラーを取得している場所です)

<link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/Docking/CSS/Widgets.css")" />

<script type="text/javascript">
    function displaySuccess(result) {
        popup.Show();
    }

    function PrepareValidationScripts(form) {
        if (!form)
            return;
        if (form.attr("data-executed"))
            return;
        $.validator.unobtrusive.parse(form); // <----- this is where I get the error
        form.attr("data-executed", "true");
    }
</script>

@{
    //this is where I render my partial views
    <snip.....>
    <snip.....>
    <snip.....>
 }
4

1 に答える 1

2

レイアウトには、最初に jQuery を含め、次に jQueryval を含める必要があります。

Scripts.Render("~/bundles/jquery"); 
Scripts.Render("~/bundles/jqueryval");

これは、jQuery.validate プラグインが jQuery に依存しており、スクリプトを含める順序が重要であるためです。

また、すべてのカスタム スクリプトを、他のメイン スクリプトのに配置される特別な専用セクションに配置することをお勧めします。

Scripts.Render("~/bundles/jquery"); 
Scripts.Render("~/bundles/jqueryval");
RenderSection("Scripts", required: false)

次に、ビュー内ですべてのスクリプトをこのセクションに配置して、順序が保持されるようにします。

@section Scripts {
    <script type="text/javascript">
        function displaySuccess(result) {
            popup.Show();
        }

        function PrepareValidationScripts(form) {
            if (!form)
                return;
            if (form.attr("data-executed"))
                return;
            $.validator.unobtrusive.parse(form);
            form.attr("data-executed", "true");
        }
    </script>
}

@{
    //this is where I render my partial views
    <snip.....>
    <snip.....>
    <snip.....>
 }

もちろん、CSS スタイルについても同じことが言えます。ドキュメントの特別な専用セクションに配置する必要<head>があります。

于 2013-02-07T21:03:07.967 に答える