MVC-jQuery UI-对话框-问题
|
我试图在不使用AjaxActionLink的情况下在MVC中抛出一个对话框窗口。在此示例中,我使用的是jQuery ui 1.8.13。
请考虑以下片段:
public class ModalViewModel
{
public string Title { get; set; }
public string Description { get; set; }
}
和控制器:
private ActionResult GetVisitors(VisitorSearchViewModel model)
{
VisitorSearchResponse response =
.... Omitted for brevity
if (response.Success)
{
return View(\"VisitorList\", response.Visitors.ToList());
}
else
{
return RedirectToAction(\"Error\");
}
}
public PartialViewResult Error()
{
return PartialView(\"Modal\",
new ModalViewModel()
{
Title = \"Test Title\",
Description = \"Test Description\"
});
}
最后,模态共享视图:
@model CraftTraxNG.Model.ViewModels.ModalViewModel
<script type=\"text/javascript\">
$(document).ready(function () {
$(\"#errorMessage\").dialog(
{ autoOpen: true,
title: \'@Model.Title\',
width: 500,
height: 100,
modal: true,
buttons:{ \"OK\": function () {
$(this).dialog(\"close\"); }
}
});
});
<div id=\"errorMessage\" style=\"display:none;\">
@Model.Description
</div>
遇到错误时,它将写出部分视图内容;即,它成功创建了具有适当样式的对话框窗口。我的问题是我想在当前视图上的某处渲染部分视图。我以前从未以这种方式使用过它。到目前为止,当它渲染该局部视图时,我会丢失当前所在视图的内容。
通常,我可以使用AjaxActionLink并仅设置希望对话框渲染的div标签,并替换它或在之后,之前插入它,等等。
在这种情况下,我将前往服务并获取响应服务器端,如果不成功,则需要一种方法用部分视图替换常规视图上的一些div标签。
任何帮助表示赞赏。
谢谢。
没有找到相关结果
已邀请:
1 个回复
苛肠倒俱
这很粗糙,但是它为您提供了一个很好的起点。