Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a pop up page link in ASP.NET MVC

Tags:

asp.net-mvc

How to generate a javascript link in asp.net mvc?

eg.

<a href="javascript:poptastic('/examples/poppedexample.html');">Pop it</a>

Can I use Html.ActionLink and how to do this?

I could do something like this:

<a href="javascript:poptastic('ItemDetail?ID=<%=item.ID%>');">Pop it</a> 

But I just want to find out will there be some better solutions for this?

Many thanks.

like image 722
Daoming Yang Avatar asked Oct 14 '22 08:10

Daoming Yang


2 Answers

Yes, you can do something like:

<%=Html.ActionLink(model.Title, "View", "PoppedView", new { Id = model.Id.ToString() }, new { target="_blank" })%> 
like image 96
Ian Nelson Avatar answered Oct 26 '22 22:10

Ian Nelson


I would look at doing this using jQuery UI and a dialog instead of a new window. You can use the open handler to load up the content into the dialog.

<%= Html.ActionLink( "Pop It",
                     "ItemDetail",
                     "Item",
                     new { ID = model.ID },
                     new { @class = "popup-link" } ) %>

<script type="text/javascript">
   $(function() {
        $('.popup-link').click( function() {
           var href = $(this).attr('href');
           $('<div><p class="popup-content"></p></div>').dialog({
              autoOpen: true,
              modal: true,
              height: 200,
              width: 400,
              open: function() {
                   $(this).find('.popup-content').load(href);
              },
              close: function() {
                   $(this).dialog('destroy');
              }
           });
           return false;
        });
   });
</script>
like image 24
tvanfosson Avatar answered Oct 26 '22 23:10

tvanfosson