Example of Print in ASP.NET MVC Rich Text Editor Control
This sample demonstrates how to print the content of the Rich Text Editor. Click the print command which is placed in the toolbar of the editor to print the editor’s content.
@* The editor's settings are in the view; the data they read (ViewData) is set in the controller action (see the controller tab). *@
@Html.UiRichTextEditor(new UiRichTextEditorOptions
{
Id = "printEditor",
ToolbarSettings = new UiRichTextToolbar { Items = (List<string>)ViewData["Tools"] },
Value = (string)ViewData["RTEValue"]
})
@Html.UiRichTextEditor(new UiRichTextEditorOptions
{
Id = "printEditor",
ToolbarSettings = new UiRichTextToolbar { Items = (List<string>)ViewData["Tools"] },
Value = (string)ViewData["RTEValue"]
})
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class RichTextEditorController : Controller
{
// The page is Views/RichTextEditor/Print.cshtml; it draws what ViewData holds.
public ActionResult Print()
{
ViewData["Tools"] = new List<string> { "Bold", "Italic", "Underline", "|", "Formats", "Alignments", "Blockquote", "OrderedList", "UnorderedList", "|", "CreateLink", "Image", "|", "SourceCode", "Undo", "Redo", "Print" };
ViewData["RTEValue"] = "<h2>The Greatest Lessons from Nature</h2><p>Nature is a powerful teacher, offering timeless wisdom through its beauty, resilience, and harmony. Here are three of the most important lessons we can learn from nature:</p>" +
"<p><strong>Adaptability & Resilience</strong> 🌿</p><p>Nature is constantly changing and evolving. Trees withstand storms, rivers carve through rocks, and animals adapt to new environments. Similarly, life challenges us, and, like nature, we must be flexible and resilient in order to overcome obstacles.</p>" +
"<p><strong>Patience & Growth</strong> 🌱</p><p>A seed does not become a tree overnight. Growth takes time, whether in nature or in our personal and professional lives. Success, wisdom, and strength develop through persistence, effort, and patience.</p>" +
"<p><strong>Balance & Harmony</strong> 🌎</p><p>Nature maintains a delicate balance throughout the day and night, across the seasons, and within ecosystems. It teaches us the importance of balance in our own lives between work and rest, giving and receiving, and action and reflection.</p>" +
"<p><br></p><p align=\"center\"><em>“Look deep into nature, and then you will understand everything better.” <strong>– Albert Einstein</strong></em></p>";
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
The Rich Text Editor prints its content from a frame of its own: the page around it is not printed. Click the Print tool in the toolbar to
print the editor’s content (or call print()).