我正在尝试从我的控制器重定向到不同的页面。然而,我在我的页面上有一个动态部分呈现设置,它将页面的一部分呈现到特定的div中。
$(document).ready(function () {
$.ajax({
url: '<%=Url.Content("~/Area/Controller/Action")%>';
success: function (data) {
$("#div1").html(data);
},
error: function (data) {
$("#div1").html(data.responseText);
}
});
});
我得到的问题是,当我尝试从控制器重定向时,我重定向到的页面在div中呈现,而不是完全重定向。
控制器:
public ActionResult Index()
{
if (condition...)
return RedirectToAction("Index", "Controller", new { Area = "Area" });
return PartialView("view", model);
}
我需要能够完全重定向到另一个页面。
发布于 2012-03-30 05:39:02
您当前正在请求jQuery用来自控制器的超文本标记语言响应填充$('#div1')
。这不是你想要的。为什么您的控制器不直接向返回URL而不是页面呢?
$.ajax({
url: '<%=Url.Content("~/Area/Controller/Action")%>';
success: function (data) {
window.location.href = data.url;
},
error: function (data) {
$("#div1").html(data.responseText);
}
});
您还包括了一个额外的结束括号,我已经删除了它。
发布于 2012-04-02 02:53:12
我只是想破解你的逻辑,让它正常工作。
public ActionResult Index()
{
if (condition...)
return new {Status = 1, Content = <your URL to Redirect to>};
return new {Status = 2, Content = PartialView("view", model)};
}
$(document).ready(function () {
$.ajax({
url: '<%=Url.Content("~/Area/Controller/Action")%>';
success: function (data) {
if(data.d.Status = 1)
{
window.location.href = data.d.Content;
}
else
{
$("#div1").html(data.d.Content);
}
},
error: function (data) {
$("#div1").html(data.responseText);
}
});
});
注意:我还没有对此进行测试。您可能需要使用它才能使其工作。另外,您可能需要将Index的返回类型更改为'object‘。
请让我知道结果。
https://stackoverflow.com/questions/9937462
复制相似问题