Open a view as a pop up

前端 未结 2 893
孤城傲影
孤城傲影 2020-12-16 03:16

Controller.cs is:

 public ActionResult ViewRequest(int id)
        {
            Job job = Jobs.GetJob(id);

            return View(job);
        }
<         


        
相关标签:
2条回答
  • 2020-12-16 03:18

    Add a class to the link:

    @Html.ActionLink("Download", "Download", new { id = model.Id }, 
                                             new{ @class = "dialog"} )
    

    And add this script somewhere:

    <script type="text/javascript">
        $(function (){
            $('a.dialog').click(function() {
                var url = $(this).attr('href');
                var dialog = $('<div style="display:none"></div>').appendTo('body');
                dialog.load(url, {}, 
                    function (responseText, textStatus, XMLHttpRequest) {
                    dialog.dialog({
                        close: function(event, ui) {
                            dialog.remove();
                        }
                    });
                });
                return false;
            });
        });
    </script>
    

    Required CSS/JS

    • jQuery UI: https://jqueryui.com/
    0 讨论(0)
  • 2020-12-16 03:39

    You could append the target="_blank" HTML attribute to the anchor if you want the url to be opened in a new browser window:

    @Html.ActionLink(
        "view request in a new window", 
        "ViewRequest", 
        new { id = model.Id }, 
        new { target = "_blank" }
    )
    

    Or if you want to open it in a new modal window you could use the jQuery UI Dialog widget you could unobtrusively AJAXify this link (after applying it an unique id):

    @Html.ActionLink(
        "view request in a new window", 
        "ViewRequest", 
        new { id = model.Id }, 
        new { id = "linkId" }
    )
    

    and then in a separate javascript file:

    $(function() {
        $('#linkId').click(function() {
            $.get(this.href, function(result) {  
                $(result).dialog();
            });
            return false;
        });
    });
    

    or if you want to open the dialog immediately when the link is clicked and provide a small feedback while the AJAX call executes:

    $(function() {
        $('#linkId').click(function() {
            $('<div>Loading ...</div>').load(this.href).dialog();
            return false;
        });
    });
    
    0 讨论(0)
提交回复
热议问题