2

ここでは、jquery を使用してダイアログ ボックス内に部分ビューを読み込もうとしています。これは私のコードです:

 $('#newdialog').dialog({
            autoOpen: false,
            width: 900,
            top: 76,
            resizable: false,
            title: 'Modify Add image',
            modal: true,
            open: function (event, ui) {
                //Load the CreateAlbumPartial action which will return 
                // the partial view _CreateAlbumPartial
                // alert(idimg);
                $(this).load("@Url.Action("GridView1","LandingSetting")");
            },
            buttons: false,
            //            {
            //                "Close": function () {
            //                    $(this).dialog("close");
            //                }
            //            },
            position: {
                my: 'top',
                at: 'top',
                of: $('.maindiv')
            }

        });

私のビューコード:

@{
    ViewBag.Title = "GridView";
    Layout = null;
}
<h2>
</h2>
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Home</title>
</head>
<body>
    <table border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td>
                <div id="HOME" style="overflow: auto; height: 560px; width: 880px; background-color: #E0E0E0;
                    color: White;">
                    @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "adform" }))
                    {
                        if (Model.Count == 0)
                        {

                        <h1 align="center">
                            Sorry No Ads Found! Please Add some ads.</h1>
                        }

                        else
                        {
                        <table>
                            <tr>
                                @{
                            int crow = 1;
                            foreach (var item in Model)
                            {
                                    <td>
                                        <ul style="list-style: none;">
                                            <li>
                                                <img src="@item.banner" width="250" height="170" />
                                            </li>
                                            <li>
                                                <input id="@item.banner" type="radio" name="one" value="@item.banner" />
                                            </li>
                                        </ul>
                                    </td>
                                if (crow % 2 == 0)
                                {                                                    
                                    <tr>
                                        <td style="width: 285px; height: 50px">
                                        </td>
                                    </tr>

                                }
                                crow++;

                            }

                                }
                            </tr>
                        </table>

                        <input id="Submit1" type="submit" value="submit" />
                        }
                    }
                </div>
            </td>
        </tr>
    </table>
</body>
</html>

このコードは localhost で正常に動作します。しかし、プロジェクトを公開してサーバーで実行すると、ダイアログ ボックスが開きますが、部分ビューが読み込まれません。何が間違っていますか? 誰でも助けてくれますか。ありがとう

編集: jquery コードは私のメイン ビューにあり、レイアウト ページの参照と必要な jquery 参照があります。そのページでボタンをクリックすると、ダイアログボックスが開き、上記のビューが読み込まれます。

4

1 に答える 1

0

これは Cross Domain Request が原因のような気がします。アクション URL が別のホスト (場合によってはサブドメインでさえも) につながる場合、そのようなリクエストを行うことができないことを示すエラーがコンソールに表示されます。とにかく、コンソールに何かが出力された場合はお知らせください。

それ以外の場合は、部分ビューから doctype、html、head、body などのタグを削除してみてください。これらのタグは既にページにあり、悪いネスト状況を作成する必要はありません。

于 2013-04-09T13:05:18.347 に答える