Home How to redirect to homepage ASP.NET MVC
Reply: 0

How to redirect to homepage ASP.NET MVC

missy brown
1#
missy brown Published in 2017-12-07 19:35:26Z

When the user clicks print/issue it produces a pdf file however; I would like the user to open the pdf file in a different tab as well as the current tab redirects to the home page; Because I already have a return; I'm not sure how to redirect to the homepage at the same time. This is what I have thus far

 <table>
                    <tr>
                        <th class="col-md-4">Item Number</th>
                        <th class="col-md-4">Item Description</th>
                        <th class="col-md-4">Expense Account</th>
                        <th class="col-md-2">Quantity Requested</th>
                        <th class="col-md-2">Quantity Issued</th>
                        <th class="col-md-1">UOM</th>
                        <th class="col-md-1">Item Price</th>

                    </tr>


                    @{
                        if (@Model.items.Count > 0)
                        {
                            foreach (var issueditem in @Model.items)
                            {
                                <tr>

                                    <td class="col-md-4">@issueditem.itemNumber</td>
                                    <td class="col-md-4">@issueditem.description</td>
                                    <td class="col-md-4">@issueditem.expense_account.getDescription</td>
                                    <td class="col-md-2">@issueditem.quantity.ToString()</td>
                                    <td class="col-md-2">@issueditem.quantityI.ToString()</td>
                                    <td class="col-md-1">@issueditem.selecteduomtext </td>
                                    <td class="col-md-1">@issueditem.price.ToString()</td>


                                    <td> @Html.ActionLink("Edit", "Edit", new { id = issueditem.lineNum }) </td>


                                </tr>
                            }

                        }


                    }



                </table>





                            <button type="submit" class="btn btn-default" formaction="@Url.Action("ReceiptPrint")">Print/Issue</button>

Controller

 public ActionResult ReceiptPrint(Issue issue)
    {
        IssueDAO dbdata = new IssueDAO();
        dbdata.connectionString = ConfigurationManager.ConnectionStrings

["TConnectionString"].ConnectionString;


        Item item = new Item();


        try
        {
            dbdata.createIssue(getIssue, item);//Creates the issue in the database
        }
        catch (Exception ex)
        {
            LogWrite logWriter = new LogWrite(ex.ToString());
            ViewBag.errorMessage = "Unable to complete the Issue. Please see Log file for more Information";
            return View("Index", getIssue);

        }
        DataSet ds = dbdata.GetReceipt(getIssue.requisitionNumber);



        LocalReport localreport = new LocalReport();
        localreport.ReportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\Reciept.rdlc";
        localreport.DataSources.Add(new ReportDataSource("Receipt_Data", ds.Tables[0]));
        localreport.SetParameters(new ReportParameter("Req_num", getIssue.requisitionNumber));

        string reporttype = "PDF";
        string mimeType;
        string encoding;
        string fileNameExtension = "pdf";
        string deviceInfo = @"<DeviceInfo>              
                 <OutputFormat>PDF</OutputFormat>              
                 <PageWidth>8.5in</PageWidth>              
                 <PageHeight>11in</PageHeight>          
                 <MarginTop>0.25in</MarginTop>          
                 <MarginLeft>0.45in</MarginLeft>            
                 <MarginRight>0.45in</MarginRight>       
                 <MarginBottom>0.25in</MarginBottom></DeviceInfo>";
        Warning[] warnings;
        string[] streams;
        byte[] renderedBytes;
        renderedBytes = localreport.Render(
         reporttype, deviceInfo, out mimeType, out encoding, out fileNameExtension,
         out streams, out warnings);


        var doc = new iTextSharp.text.Document();
        var reader = new PdfReader(renderedBytes);
        using (FileStream fs = new FileStream(Server.MapPath("~/Receipt" +
             Convert.ToString(Session["CurrentUserName"]) + ".pdf"), FileMode.Create))
        {
            PdfStamper stamper = new PdfStamper(reader, fs);
            string Printer = "Xerox Phaser 3635MFP PCL6";
            // This is the script for automatically printing the pdf in acrobat viewer
            stamper.JavaScript = "var pp = getPrintParams();pp.interactive =pp.constants.interactionLevel.automatic; pp.printerName = " +
                           Printer + ";print(pp);\r";
            stamper.Close();
        }
        reader.Close();
        FileStream fss = new FileStream(Server.MapPath("~/Receipt.pdf"), FileMode.Open);
        byte[] bytes = new byte[fss.Length];
        fss.Read(bytes, 0, Convert.ToInt32(fss.Length));
        fss.Close();
        System.IO.File.Delete(Server.MapPath("~/Receipt.pdf"));
        return File(bytes, "application/pdf");


    }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30584 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO