Example of Insert Media in ASP.NET MVC Rich Text Editor Control
This sample demonstrates the option to insert media into the Rich Text Editor content. Click the audio and video button from the toolbar item to insert the media.
@* 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 = "mediaEditor",
ToolbarSettings = new UiRichTextToolbar { Items = (List<string>)ViewData["Tools"] },
QuickToolbarSettings = new UiRichTextQuickToolbar { Video = (List<string>)ViewData["Video"], Audio = (List<string>)ViewData["Audio"] },
Value = (string)ViewData["RTEValue"]
})
@Html.UiRichTextEditor(new UiRichTextEditorOptions
{
Id = "mediaEditor",
ToolbarSettings = new UiRichTextToolbar { Items = (List<string>)ViewData["Tools"] },
QuickToolbarSettings = new UiRichTextQuickToolbar { Video = (List<string>)ViewData["Video"], Audio = (List<string>)ViewData["Audio"] },
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/InsertMedia.cshtml; it draws what ViewData holds.
// The files under ~/Content are the demo's own sample files: put yours at those paths, or change the addresses.
public ActionResult InsertMedia()
{
ViewData["Tools"] = new List<string> { "Bold", "Italic", "Underline", "|", "Formats", "Alignments", "Blockquote", "OrderedList", "UnorderedList", "|", "CreateLink", "Image", "Audio", "Video", "|", "SourceCode", "Undo", "Redo" };
ViewData["Video"] = new List<string> { "Replace", "Align", "Remove", "VideoLayoutOption", "VideoDimension" };
ViewData["Audio"] = new List<string> { "Replace", "Remove", "AudioLayoutOption" };
ViewData["RTEValue"] = "<p>Rich Text Editor allows inserting video and audio from online sources and the local computers where you want to insert a video and audio into your content.</p>" +
"<p><b>Get started with a video</b></p><p>Use the Video tool to replace or add a video.</p>" +
"<p><video controls src=\"" + Url.Content("~/Content/media/sample.webm") + "\" width=\"300\"></video></p>" +
"<p><b>Get started with an audio</b></p><p>Use the Audio tool to replace or add an audio.</p>" +
"<p><audio controls src=\"" + Url.Content("~/Content/media/sample.wav") + "\"></audio></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>
Video tools are used to insert a video into the Rich Text Editor, from an http or https address or one on this site; click on the video to customize it using the quick toolbar. The quick toolbar has the following items:
Replace– can replace the video with some other video.Align– Align the video with left, center and right (the video gets a paragraph of its own).Delete– delete the video.LayoutOption– display the video inline, or with a break (in a paragraph of its own).Resize– can resize the video width (VideoDimension).
Audio tools are used to insert an audio into the Rich Text Editor; click on the audio to customize it using the quick toolbar. The quick toolbar has the following items:
Replace– can replace the audio with some other audio.Delete– delete the audio.Display– display the audio inline, or with a break.
The player has the browser’s controls; the HTML keeps only the address, the controls and the width, never a script or an embedded page. The browser’s audio controls take every click, so click the empty part of the audio’s paragraph, or press Tab to the player and Alt+F10 to move into its toolbar.
Note: For security reasons, an embedded video address (a page that plays it) is not taken: insert the address of the media file. The sample
plays a video file (.webm) and an audio file (.wav) of this site.