Controller.cs is:
public ActionResult ViewRequest(int id)
{
Job job = Jobs.GetJob(id);
return View(job);
}
<
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
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;
});
});