2017-02-14 5 views
0

電子メールと添付ファイルの送信actalyが動作します。私の問題は、私はタイプの例外「のSystem.Exception」のRotativa.dllで発生したMail pdf Rotativaを使用した添付ファイル

「生成されたPDF」を送信しようとしているが、ユーザーコードで処理されていなかった、このエラーを取得することです

追加情報:エラー:失敗したロードページhttp://localhost:49224/Offer/OfferPdf/4(時にはそれが--load-エラー処理でちょうどこのエラーを無視していきます無視)

コントローラでのメールテスト:

public ActionResult MailTest() 
    { 



     MailMessage msg = new MailMessage(); 
     msg.To.Add(new MailAddress(CoEmail)); 
     msg.From = new MailAddress(MailFrom, UserName); 
     msg.Subject = "Offer"; 
     msg.Body = "This is a Test"; 
     MemoryStream stream = new MemoryStream(OffersPdfMail (4, "Offer")); 
     Attachment att1 = new Attachment(stream, "Offer.pdf", "application/pdf"); 
     msg.Attachments.Add(att1); 
     msg.IsBodyHtml = true; 
     msg.BodyEncoding = System.Text.Encoding.UTF8; 
     msg.SubjectEncoding = System.Text.Encoding.Default; 

     SmtpClient client = new SmtpClient(); 
     client.UseDefaultCredentials = false; 
     client.Credentials = new System.Net.NetworkCredential(User, Pass); 
     client.Port = 587; // 
     client.Host = "smtp.office365.com"; 
     client.DeliveryMethod = SmtpDeliveryMethod.Network; 
     client.EnableSsl = true; 
     try 
     { 
      client.Send(msg); 
      return RedirectToAction("index"); 

     } 
     catch (Exception ex) 
     { 
      return HttpNotFound(); 
     } 

    } 

バイト[]:

public Byte[] OfferPdfMail(int? id, string filename) 
    { 
    var mailpdft = new ActionAsPdf("OfferPdf/4") 
     { 
      FileName = "Offer", 
      PageSize = Rotativa.Options.Size.A4, 






      PageWidth = 210, 

      PageHeight = 297 

     }; 
     Byte[] PdfData = mailpdft.BuildPdf(ControllerContext); 
     return PdfData; 

とViewasPdf最後:英語へ

 public ActionResult OfferPdf (int? id, string filename) 
    { 
     string footer = "test" ; 
     if (id == null) 
     { 
      return new HttpStatusCodeResult(HttpStatusCode.BadRequest); 
     } 




     var pdf = new ViewAsPdf("TilbudsPdf") { 
      FileName = filename, 
      PageSize = Rotativa.Options.Size.A4, 

      PageOrientation = Rotativa.Options.Orientation.Portrait, 

      PageMargins = new Rotativa.Options.Margins(12, 12, 12, 12),// it’s in millimeters 

      PageWidth = 210, 

      PageHeight = 297, 
      CustomSwitches = footer }; 

     return pdf; 
    } 

Editted名前を。いくつかを逃したかもしれない。 ご迷惑をおかけして、ありがとうございました。 よろしくお願いします。Eric

答えて

0

解決策を見つけました。私はpdfのpdfを作ろうとしていたからです。だから私はこのような新しいActionResultメソッドを作った:

public ActionResult tilbudspdfMailView(int? id, string filename) 
    { 
     Offer Offer= db.Offer.Find(id); 

     return View("OfferPdf", Offer); 
} 
関連する問題