这里我尝试使用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 中正常工作。但是当我发布我的项目并在服务器上运行时,对话框会打开,但是parial视图是不加载。我做错了什么?任何人都可以帮忙。谢谢
编辑:jquery代码在我的主视图上,它有一个布局页面引用以及所需的jquery引用。在该页面中,如果我单击一个按钮,则应打开该对话框,并在其中加载上述视图。
答案 0 :(得分:0)
我感觉这是由跨域请求引起的。如果您的操作网址指向其他主机(可能甚至是子域),您的控制台中会出现错误,指出您无法提出此类请求。无论如何,如果您的控制台确实输出了一些东西,请告诉我们。
否则尝试从局部视图中删除doctype,html,head,body等标签,您已经在页面上有那些不需要创建错误的嵌套情况。