如何在MVC 4中的同一视图中打开窗口? [英] How to open window in the same View in MVC 4?

查看:16
本文介绍了如何在MVC 4中的同一视图中打开窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a Telerik MVC grid in my view with a "Download" custom button. This button redirects to my Download action and this download action redirects me to the download view which shows me some images in window mode. I would like to open this window with the grid 'under' it, in the same page.

我的代码:

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<string>();
     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(@<text>
@using (Html.BeginForm())
{
    foreach (var uri in ViewBag.uris)
    {
    <img src="@uri" alt="IMAGE"/>
    <a href="@uri">@uri</a>
    }
}
   </text>).Render();
}

这很好用,但是当我点击下载按钮时我丢失了我的网格.有什么建议?谢谢.

This works fine, but i lose my grid when i click in the download button. Any suggestions? Thanks.

推荐答案

所以你想在你的脚本标签中放置一个 ajax 调用.确保您在页面上引用了 jquery.你打电话应该是这样的

so you want to put an ajax call in your script tag. Make sure you have jquery referenced on the page. you call should look something like this

$('#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 覆盖,但有几个不同的选项).希望这有帮助

so when a row is clicked the method on your controller is called and a partial view is returned. Put that result into a div on your view and then pop up that div (we use jquery overlay but there are several different options). Hope this helps

这篇关于如何在MVC 4中的同一视图中打开窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆