如何在MVC 4中的同一视图中打开窗口?

我在视图中有一个Telerik MVC网格,带有“下载”自定义按钮。 此按钮重定向到我的下载操作,此下载操作将我重定向到下载视图,该视图以窗口模式显示一些图像。 我想在同一页面打开这个窗口,网格’在’下面。

我的代码:

c.Bound(column => column.IsStock); c.Bound(column => column.Version); c.Command(cmd => cmd.Custom("Download") .Text("Download") .DataRouteValues(d => { d.Add(k => k.IDDocument); d.Add(k => k.ReceivedDate); }) .SendDataKeys(true) .Action("Download", "Administrative")); 

行动:

  [Authorize(Roles = "Administrator, Employee")] public ActionResult Download(DocumentModel model) { var listUris = new List(); var uris = ServiceProxy.GetInstance().GetContainerUri(model.IDProtocol.ToString(), model.IDDocument.ToString())); foreach (var uri in uris) { listuris.Add(uri.AbsoluteUri); } ViewBag.uris = listUris; return View("Download"); } 

下载查看:

 @{ ViewBag.Title = "Imagens"; } @{ Html.Telerik().Window() .Draggable(true) .Resizable(a => a.Enabled(true)) .Scrollable(true).Width(700) .Name("ShowBarcode") .Modal(true) .Buttons(b => b.Close()) .Content(@ @using (Html.BeginForm()) { foreach (var uri in ViewBag.uris) { IMAGE https://stackoverflow.com/questions/20071301/how-to-open-window-in-the-same-view-in-mvc-4/@uri } } ).Render(); } 

这工作正常,但当我点击下载按钮时,我丢失了网格。 有什么建议? 谢谢。

所以你想在你的脚本标签中放一个ajax调用。 确保页面上引用了jquery。 你打电话应该看起来像这样

 $('#TableID tr').on('click', function() { $.ajax({ url: "@(Url.Action("Action", "Controller"))", type: "POST", data: { id: $(this).attr('id')// from here http://stackoverflow.com/questions/5142422/get-id-of-selected-row-in-a-table-html } cache: false, async: true, success: function (result) { $(".Content").html(result); contentOverlay.load(); } }); }); 

然后在你的控制器上

 public PartialViewResult Action(string id){ Model model = //query the database return PartialView("_PartialView", model); } 

因此,当单击一行时,将调用控制器上的方法并返回部分视图。 将该结果放入视图中的div,然后弹出该div(我们使用jquery overlay,但有几个不同的选项)。 希望这可以帮助