2017-11-23 8 views
1

私はmvcコアアプリケーションに取り組んでいます。私はpdfにビューを変換する必要があります。 そのためにはRotativa.NetCoreNugGet Pakagesにあります。Rotativaを使ってMvc CoreビューをPDFに変換

enter image description here

しかし、それは動作しません。例外を通じ

public class TestViewModel 
    { 
     public int DocId { get; set; } 
     public string DocContent { get; set; } 
    } 

public class RotativaController : Controller 
    { 
     public ActionResult Index() 
     { 
      ViewBag.Message = string.Format("Hello to ASP.NET MVC Core!"); 
      return View(); 
     } 

     //Convert Index View To PDF 
     public ActionResult PrintIndex() 
     { 
      return new ActionAsPdf("Index"); 
     } //Not working. 

     //Convert TestViewModel Model To PDF 
     public ActionResult PrintTestViewModel() 
     { 
      List<TestViewModel> _list = new List<TestViewModel>(); 
      _list.Add(new TestViewModel { DocId = 1, DocContent = "Content 1" }); 
      _list.Add(new TestViewModel { DocId = 2, DocContent = "Content 2" }); 
      _list.Add(new TestViewModel { DocId = 3, DocContent = "Content 3" }); 
      _list.Add(new TestViewModel { DocId = 4, DocContent = "Content 4" }); 
      _list.Add(new TestViewModel { DocId = 5, DocContent = "Content 5" }); 
      return new ViewAsPdf(_list); 
     } //Not working. 
    } 

TypeLoadException: Could not load type 'Microsoft.AspNetCore.Builder.CookieAuthenticationOptions' from assembly 'Microsoft.AspNetCore.Authentication.Cookies, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. 
+0

この問題のアップデートはありますか? – AFetter

答えて

-1

としてあなたは、アクション "インデックス" の[のAllowAnonymous]を使用する必要があります。 それ以外の場合は、FormsAsuthenticationCookieNameプロパティとCookiesプロパティをActionAsPdfに設定します。

0

解決策は簡単です。

現時点では、現在のブランチは.NetCoreApp 1.0です。

.netcoreを2.0に更新するのを待っているプル要求があります。その後

<TargetFrameworks>netcoreapp2.0</TargetFrameworks> 

    <ItemGroup> 
    <PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.0" /> 
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" /> 
    </ItemGroup> 

、プロジェクトを再読み込み、CookieAuthenticationOptionsで問題を解決し、それはそれである:

簡単な回避策は、解決策をダウンロードアンロードプロジェクト、次の行を更新することです。

0

CookieAuthenticationOptionsクラスは、NetCore 2.0ではなくNetCore 1.xにのみ適用されます。その後、https://github.com/aaxelm/Rotativa.NetCore/pull/1/files?diff=splitとビジュアルで、あなたのソリューションに既存のプロジェクトとしてこのプロジェクトを追加します。

あなたはGitHubのからRotativa.NetCoreのソースコードダウンロードする必要がRotativa.NetCoreがNetCore 2.0上で動作するように取得するには:ここで説明する変更を行い、https://github.com/aaxelm/Rotativa.NetCoreをスタジオ。

関連する問題