Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Rotativa.AspNetCore.DemoApp/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Rotativa.AspNetCore.DemoApp.Models;
using System.Diagnostics;
using Rotativa.AspNetCore.Options;
using System.Data.Common;

namespace Rotativa.AspNetCore.DemoApp.Controllers
{
Expand Down Expand Up @@ -30,6 +31,22 @@ public IActionResult Privacy()
return new ViewAsPdf();
}

public IActionResult EphemerideWithAction()
{
return new ActionAsPdf("Ephemeride", new { d=DateTime.Now , day= DateTime.Now.DayOfWeek.ToString() } );
}

public IActionResult Ephemeride( DateTime d, string day)
{
Ephemeride ephemeride = new Ephemeride();
ephemeride.DateOfTheDay = d;
ephemeride.TheDayToday = day;

ViewBag.testViewBag = new List<string> { "val 1", " val 2" };

return View("EphemerideDemo", ephemeride);
}

public IActionResult ContactImage()
{
ViewData["Message"] = "Your contact page image.";
Expand Down
9 changes: 9 additions & 0 deletions Rotativa.AspNetCore.DemoApp/Models/Ephemeride.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Rotativa.AspNetCore.DemoApp.Models
{
public class Ephemeride
{
public DateTime? DateOfTheDay { get; set; }
public string? TheDayToday { get; set; }

}
}
26 changes: 26 additions & 0 deletions Rotativa.AspNetCore.DemoApp/Views/Home/EphemerideDemo.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@model Rotativa.AspNetCore.DemoApp.Models.Ephemeride

@{
ViewData["Title"] = "Ephemeride";
List<string> testViewBag = ViewBag.testViewBag as List<string>;
}
<h2>@ViewData["Title"]</h2>
<h3>@ViewData["Message"] </h3>

<div>
<h1>@Model.DateOfTheDay</h1>
<p>@Model.TheDayToday</p>
</div>

<div>
<h2>ViewBag Content : </h2>
<ul>
@if (testViewBag != null)
{
foreach (var item in testViewBag)
{
<li>@item</li>
}
}
</ul>
</div>
3 changes: 3 additions & 0 deletions Rotativa.AspNetCore.DemoApp/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="PrivacyImage">Privacy Image</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="EphemerideWithAction">Ephemeride with action</a>
</li>
</ul>
</div>
</div>
Expand Down
59 changes: 59 additions & 0 deletions Rotativa.AspNetCore/ActionAsImage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;

namespace Rotativa.AspNetCore
{
public class ActionAsImage : AsImageResultBase
{
private RouteValueDictionary _routeValuesDict;
private object _routeValues;
private string _action;

public ActionAsImage(string action) : base()
{
_action = action;
}

public ActionAsImage(string action, RouteValueDictionary routeValues)
: this(action)
{
_routeValuesDict = routeValues;
}

public ActionAsImage(string action, object routeValues)
: this(action)
{
_routeValues = routeValues;
}

protected override string GetUrl(ActionContext context)
{
var urlHelperFactory = context.HttpContext.RequestServices.GetRequiredService<IUrlHelperFactory>();
var urlHelper = urlHelperFactory.GetUrlHelper(context);

string actionUrl;
if (_routeValues == null)
{
actionUrl = urlHelper.Action(_action, _routeValuesDict);
}
else if (_routeValues != null)
{
actionUrl = urlHelper.Action(_action, _routeValues);
}
else
{
actionUrl = urlHelper.Action(_action);
}

var currentUri = new Uri(context.HttpContext.Request.GetDisplayUrl());
var authority = currentUri.GetComponents(UriComponents.StrongAuthority, UriFormat.Unescaped);

var url = $"{context.HttpContext.Request.Scheme}://{authority}{actionUrl}";
return url;
}
}
}
59 changes: 59 additions & 0 deletions Rotativa.AspNetCore/ActionAsPdf.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;

namespace Rotativa.AspNetCore
{
public class ActionAsPdf : AsPdfResultBase
{
private RouteValueDictionary _routeValuesDict;
private object _routeValues;
private string _action;

public ActionAsPdf(string action) : base()
{
_action = action;
}

public ActionAsPdf(string action, RouteValueDictionary routeValues)
: this(action)
{
_routeValuesDict = routeValues;
}

public ActionAsPdf(string action, object routeValues)
: this(action)
{
_routeValues = routeValues;
}

protected override string GetUrl(ActionContext context)
{
var urlHelperFactory = context.HttpContext.RequestServices.GetRequiredService<IUrlHelperFactory>();
var urlHelper = urlHelperFactory.GetUrlHelper(context);

string actionUrl;
if (_routeValues == null)
{
actionUrl = urlHelper.Action(_action, _routeValuesDict);
}
else if (_routeValues != null)
{
actionUrl = urlHelper.Action(_action, _routeValues);
}
else
{
actionUrl = urlHelper.Action(_action);
}

var currentUri = new Uri(context.HttpContext.Request.GetDisplayUrl());
var authority = currentUri.GetComponents(UriComponents.StrongAuthority, UriFormat.Unescaped);

var url = $"{context.HttpContext.Request.Scheme}://{authority}{actionUrl}";
return url;
}
}
}