jquery - 发布项目后对话框未在服务器中加载 View

标签 jquery asp.net-mvc dialog

这里我尝试使用 jquery 在对话框中加载部分 View 。这是我的代码:

 $('#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>

此代码在本地主机中运行良好。但是当我发布我的项目并在服务器上运行它时,对话框将打开,但部分 View 为没有加载。我做错了什么?谁能帮忙。谢谢

编辑:jquery 代码位于我的主视图上,其中包含布局页面引用以及所需的 jquery 引用。在该页面中,如果我单击按钮,则应打开对话框,并且应在其中加载上述 View 。

最佳答案

我感觉这是由跨域请求引起的。如果您的操作网址指向不同的主机(甚至可能是子域),您的控制台中将会出现错误,指出您无法发出此类请求。无论如何,如果您的控制台确实输出了一些内容,请告诉我们。

否则,请尝试从部分 View 中删除 doctype、html、head、body 等标记,您的页面上已经有这些标记,无需创建不良的嵌套情况。

关于jquery - 发布项目后对话框未在服务器中加载 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15876212/

相关文章:

javascript - jquery 切换无法正常工作

javascript - ES6 字符串插值和 jQuery $ 的冲突

asp.net-mvc - 如何通过 Bootstrap 多选创建带有复选框的下拉菜单?

jquery - 如何在jquery对话框中获取表单中的复选框值?

javascript - Jquery ui 对话框模态 True

winforms - 防止出现未处理异常的 "[YourProgramName] has stopped working"对话框

jquery - 使用 jquery 访问 ajax html 响应的元素

javascript - 使用javascript在元素html标题中换行

jquery - Eonasdan 的 Bootstrap-Datetimepicker 无法在模态中工作

asp.net - 如何处理 url 搜索词中的 web.config