-1

私は次のコードを持っています:

<html> <head>
      <!-- Required CSS --> <link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/2.9.0/build/treeview/assets/skins/sam/treeview.css"> <!-- Optional CSS for for date editing with Calendar--> <link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/2.9.0/build/calendar/assets/skins/sam/calendar.css"> <!-- Dependency source file -->  <script src="http://yui.yahooapis.com/2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"
></script> <!-- Optional dependency source file -->  <script src="http://yui.yahooapis.com/2.9.0/build/animation/animation-min.js" type="text/javascript"></script> <!-- Optional dependency source file for date editing with Calendar-->  <script src="http://yui.yahooapis.com/2.9.0/build/calendar/calendar-min.js"
></script> <!-- Optional dependency source file to decode contents of yuiConfig markup attribute-->  <script src="http://yui.yahooapis.com/2.9.0/build/json/json-min.js" ></script> <!-- TreeView source file -->  <script src="http://yui.yahooapis.com/2.9.0/build/treeview/treeview-min.js"
></script>
     </head> <body class="yui-skin-sam">

@model IEnumerable< ESimSol.BusinessObjects.MenuTreeNode>           

<input type="button" id="btnAdd" value="Refresh" /> <label id="lblTest"> </label> <div id="treeDiv1"> <ul>    
    @foreach (var item in Model)
    {
        if (item.ParentID == 0)
        {
            <li>
                @Html.DisplayFor(modelItem => item.MenuName)  
                <ul>
                    @Html.Partial("TreeViewControl", item)   
                </ul>
             </li> 
        }
    }   </ul> </div> </body> </html>


<script type="text/javascript">

    $(document).ready(function () {
        treeInit();
    });

    var tree;
    function treeInit() {
        tree = new YAHOO.widget.TreeView(document.getElementById("treeDiv1"));
    }

</script>

スクリプトを実行したいとき、次の例外に直面します:

Microsoft JScript runtime error: Object expected

MVC3 RAZOR Viewエンジンで実行するjavascriptの完全なリファレンスを教えてください。

4

1 に答える 1

0

MVC3/Razor で JavaScript を使用することは、他のページで使用することと同じであることに注意してください。JS はクライアント側の言語であるため、常にレンダリングされた HTML で動作します。

JS コードのエラーとして目立ったものはありませんが、<script>要素は要素内にある必要があり<body>ます。ほとんどのブラウザはそれを問題なく処理するので、それがあなたの問題であるとは思えません。

スクリプト参照をチェックして、それらが正しいことを確認してから、スクリプトをさらに調べることをお勧めします。IE で発生するスクリプト エラーは、行番号を参照する必要があります。これを使用して、ページ ソース (カミソリ ページではなく、レンダリングされたページ) を調べて、エラーの原因を突き止めることができます。

于 2012-06-24T14:55:27.653 に答える