Yeah you can do some tricky works to simulate what you want:
1) Call your controller from a view by ajax. 2) Return your View
3) Use something like the following in the success
(or maybe error
! error works for me!) section of your $.ajax request:
$("#imgPrint").click(function () {
$.ajax({
url: ...,
type: 'POST', dataType: 'json',
data: $("#frm").serialize(),
success: function (data, textStatus, jqXHR) {
//Here it is:
//Gets the model state
var isValid = '@Html.Raw(Json.Encode(ViewData.ModelState.IsValid))';
// checks that model is valid
if (isValid == 'true') {
//open new tab or window - according to configs of browser
var w = window.open();
//put what controller gave in the new tab or win
$(w.document.body).html(jqXHR.responseText);
}
$("#imgSpinner1").hide();
},
error: function (jqXHR, textStatus, errorThrown) {
// And here it is for error section.
//Pay attention to different order of
//parameters of success and error sections!
var isValid = '@Html.Raw(Json.Encode(ViewData.ModelState.IsValid))';
if (isValid == 'true') {
var w = window.open();
$(w.document.body).html(jqXHR.responseText);
}
$("#imgSpinner1").hide();
},
beforeSend: function () { $("#imgSpinner1").show(); },
complete: function () { $("#imgSpinner1").hide(); }
});
});