Hi, I'm trying to create an app witch create payment recipies. What I'm trying to to is when the CreateView submit return the IndexView as normal, but at the same time open a new tab with the recipt to be print.
It might be clearer for users to show the receipt and then navigate from the receipt to the index view.
If you feel it's better because the receipt view can only contain stuff to be printed you can use @media print rules to show a navbar on screen but to use display:none for this navbar when printing.
Due to browsers blocking pop up ads, there is not really a way to do what you want. Nowadays you can only open a new window/tab from an anchor or submit button click via the target. This means the original page is unchanged.
You best best as suggested is a link to open the separate receipt.
According to your descriptions,I suggest you could use document.referrer to judge original page,and open new tab with print by javascript,
for example:
when you click submit button in Create View,it will jump to
post action:
[HttpPost]
public ActionResult Create([Bind(Include = "xxxx,xxx")] Model mod)
{
if (ModelState.IsValid)
{
db.xxx.Add(mod);
db.SaveChanges();
return RedirectToAction("Index");//return Index View
}
return View(mod);
}
in Index view:
@section scripts
{
<script>
$(function () {
if (document.referrer.indexOf("Create")>0)//if it redirect by Create View
{
var myWindow = window.open('', '', 'width=600,height=600');
myWindow.document.write("<p>This is 'myWindow'</p>");
myWindow.document.close();
myWindow.focus();
myWindow.print();
myWindow.close();
}
})
</script>
}
How it works:
Best Regards.
Yuki Tao
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
4 Points
4 Posts
Open a new tab and redirect
Jul 23, 2019 12:22 PM|guillos|LINK
Hi, I'm trying to create an app witch create payment recipies. What I'm trying to to is when the CreateView submit return the IndexView as normal, but at the same time open a new tab with the recipt to be print.
Thanks for your help!
I atache an image with what I want to do:
Participant
850 Points
492 Posts
Re: Open a new tab and redirect
Jul 23, 2019 01:39 PM|AddWeb Solution|LINK
Hello, guillos
Please refer below link hope you will get your below link.
https://stackoverflow.com/questions/14509616/open-mvc-view-in-new-window-from-controller
Thanks.
All-Star
48520 Points
18073 Posts
Re: Open a new tab and redirect
Jul 23, 2019 01:58 PM|PatriceSc|LINK
It might be clearer for users to show the receipt and then navigate from the receipt to the index view.
If you feel it's better because the receipt view can only contain stuff to be printed you can use @media print rules to show a navbar on screen but to use display:none for this navbar when printing.
All-Star
58194 Points
15658 Posts
Re: Open a new tab and redirect
Jul 23, 2019 02:07 PM|bruce (sqlwork.com)|LINK
You best best as suggested is a link to open the separate receipt.
Contributor
3710 Points
1431 Posts
Re: Open a new tab and redirect
Jul 24, 2019 06:15 AM|Yuki Tao|LINK
Hi guillos,
According to your descriptions,I suggest you could use document.referrer to judge original page,and open new tab with print by javascript,
for example:
when you click submit button in Create View,it will jump to post action:
[HttpPost] public ActionResult Create([Bind(Include = "xxxx,xxx")] Model mod) { if (ModelState.IsValid) { db.xxx.Add(mod); db.SaveChanges(); return RedirectToAction("Index");//return Index View } return View(mod); }
in Index view:
@section scripts { <script> $(function () { if (document.referrer.indexOf("Create")>0)//if it redirect by Create View { var myWindow = window.open('', '', 'width=600,height=600'); myWindow.document.write("<p>This is 'myWindow'</p>"); myWindow.document.close(); myWindow.focus(); myWindow.print(); myWindow.close(); } }) </script> }
How it works:
Best Regards.
Yuki Tao
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.