I have been trying for 4 days to solve this problem. But I cannot return json data into a new tab page.
My code:
<script type="text/javascript">
function CustomerId() {
var url = "Home/PanelGoster"; // My URL
var veri = {
Id: Id.GetValue(),
};
$.ajax({
url: "/Home/PanelGoster",
type: "POST",
dataType: "json",
contentType: 'application/json',
data: JSON.stringify(veri),
success: function (mydata) {
if (mydata.error6 == true) {
}
else { // Success
var something = window.open(url, '_blank'); // Problem Here , it does not work
something.focus(); // Problem Here
("#MusterilerGetir").html(mydata); // Problem Here, should be displayed in a new tab
}
},
error: function () {
}
});
return false;
}
</script>
Controller:
public ActionResult PanelGoster(MyModel model)
{
var stringView = RenderRazorViewToString("PartialView", MyModel());
return Json(stringView, JsonRequestBehavior.AllowGet);
}
}
I have been trying for 4 days to solve this problem. But I cannot return json data into a new tab page.
My code:
<script type="text/javascript">
function CustomerId() {
var url = "Home/PanelGoster"; // My URL
var veri = {
Id: Id.GetValue(),
};
$.ajax({
url: "/Home/PanelGoster",
type: "POST",
dataType: "json",
contentType: 'application/json',
data: JSON.stringify(veri),
success: function (mydata) {
if (mydata.error6 == true) {
}
else { // Success
var something = window.open(url, '_blank'); // Problem Here , it does not work
something.focus(); // Problem Here
("#MusterilerGetir").html(mydata); // Problem Here, should be displayed in a new tab
}
},
error: function () {
}
});
return false;
}
</script>
Controller:
public ActionResult PanelGoster(MyModel model)
{
var stringView = RenderRazorViewToString("PartialView", MyModel());
return Json(stringView, JsonRequestBehavior.AllowGet);
}
}
Share
Improve this question
edited Dec 22, 2016 at 13:08
user2418306
2,3821 gold badge23 silver badges33 bronze badges
asked Oct 26, 2013 at 13:31
user2902180user2902180
1,0413 gold badges12 silver badges12 bronze badges
4
- Why are you returning a json if you want to show your view in a new window? Simply return your view; – MRB Commented Oct 26, 2013 at 13:50
- How e?Do you have any example ? – user2902180 Commented Oct 26, 2013 at 13:52
- You return a json object, so browser will show only the text of your view. instead of json return PartialView – MRB Commented Oct 26, 2013 at 13:56
- What do you remend ? – user2902180 Commented Oct 26, 2013 at 13:57
1 Answer
Reset to default 12try
something = window.open("data:text/json," + encodeURIComponent(mysdata),
"_blank");
something.focus();
from Open a new tab/window and write something to it?