When a link is clicked, I want to open a new window with content determined by a post to my MVC controller. Here's how I currently approach it:
jQuery.ajax({
type: "POST",
url: '/controller/mycontroller',
data: { mydata: data },
error: function (xhr, status, error) {
},
success: function (response) {
win_detail = window.open('', 'name');
win_detail.document.write(response);
}
});
My controller is handling the HTML content and Response.ContentType and storing them in the ViewBag. In mycontroller.cshtml file, I have this structure:
@{
Response.ContentType = ViewBag.ContentType;
}
<head></head>
<body>
@ViewBag.MyHtml
</body>
The ContentType is not being set properly with this method. Any suggestions on how to achieve this? I'm open to changing my current structure for a solution.