Search results

Image

RichTextEditor allows to insert images from online sources as well as local computer where you want to insert the image in your content. For inserting the image to the RichTextEditor, the following list of options have been provided in the InsertImageSettings

Options Description
AllowedTypes Specifies the extensions of the image types allowed to insert on bowering and passing the extensions with comma separators. For example, pass allowedTypes as .jpg and .png.
Display Sets the default display for an image when it is inserted in to the RichTextEditor. Possible options are: ‘inline’ and ‘break’.
Width Sets the default width of the image when it is inserted in the RichTextEditor.
Height Sets the default height of the image when it is inserted in the RichTextEditor.
SaveUrl Provides URL to map the action result method to save the image.
Path Specifies the location to store the image.
Resize To enable resizing for image element.
MinWidth Defines the maximum Width of the image.
MaxWidth Defines the maximum Width of the image.
MinHeight Defines the minimum Height of the image.
MaxHeight Defines the maximum Height of the image.
ResizeByPercent Image resizing should be done by percentage calculation.

Upload Options

Through the browse option in the Image dialog, select the image from the local machine and insert into the RichTextEditor content.

If the path field is not specified in the InsertImageSettings, the image will be converted into blob url for the image will be created and the generated url will be set as src property of <img> tag as below.

In the below sample, the image has been load from the local machine and it will be saved in the given location.

razor
controller.cs
@{
    string value = @" <p>
            The RichTextEditor control is WYSIWYG ('what you see is what you get') editor that provides the best user experience to create and update the content.
            Users can format their content using standard toolbar commands.
        </p>
        <p><b> Key features:</b></p>
        <ul>
            <li><p> Provides &lt; IFRAME &gt; and &lt; DIV &gt; modes </p></li>
            <li><p> Capable of handling markdown editing.</p></li>
            <li><p> Contains a modular library to load the necessary functionality on demand.</p></li>
            <li><p> Provides a fully customizable toolbar.</p></li>
            <li><p> Provides HTML view to edit the source directly for developers.</p></li>
            <li><p> Supports third - party library integration.</p></li>
            <li><p> Allows preview of modified content before saving it.</p></li>
            <li><p> Handles images, hyperlinks, video, hyperlinks, uploads, etc.</p></li>
            <li><p> Contains undo / redo manager.</p></li>
            <li><p> Creates bulleted and numbered lists.</p></li>
        </ul>";
}

@Html.EJS().RichTextEditor("image").ToolbarSettings(e => e.Items((object)ViewBag.items)).InsertImageSettings(obj => obj.Display("inline")).Value(value).Render()
public class HomeController : Controller
{
    public ActionResult Index()
    {
        ViewBag.items = new[] { "Image" };
        return View();
    }
}

Server Side Action

The selected image can be uploaded to the required destination by using the below controller action. Map this method name in saveUrl property of InsertImageSettings and provide required destination path through path property.

razor
saveFile.cs
@{
    string value = @"<p>
    The RichTextEditor control is WYSIWYG ('what you see is what you get') editor that provides the best user experience to create and update the content.
    Users can format their content using standard toolbar commands.
</p>
<p><b> Key features:</b></p>
<ul>
    <li><p> Provides &lt; IFRAME &gt; and &lt; DIV &gt; modes </p></li>
    <li><p> Capable of handling markdown editing.</p></li>
    <li><p> Contains a modular library to load the necessary functionality on demand.</p></li>
    <li><p> Provides a fully customizable toolbar.</p></li>
    <li><p> Provides HTML view to edit the source directly for developers.</p></li>
    <li><p> Supports third - party library integration.</p></li>
    <li><p> Allows preview of modified content before saving it.</p></li>
    <li><p> Handles images, hyperlinks, video, hyperlinks, uploads, etc.</p></li>
    <li><p> Contains undo / redo manager.</p></li>
    <li><p> Creates bulleted and numbered lists.</p></li>
</ul>";
}

@Html.EJS().RichTextEditor("image-save").InsertImageSettings(obj => obj.SaveUrl("/Home/Index").Path("../Images/")).Value(value).Render()
public class HomeController : Controller
{

    public ActionResult Index()
    {
        return View();
    }

    [AcceptVerbs("Post")]
    public ActionResult Index(HttpPostedFileBase UploadFiles)
    {
        if (UploadFiles != null)
        {
            string path = Server.MapPath("~/Uploads/");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            UploadFiles.SaveAs(path + Path.GetFileName(UploadFiles.FileName));
            ViewBag.Message = "File uploaded successfully.";
        }
        return View();
    }
}

Image Delete

If you want to remove am image from the RichTextEditor content, select the image and click “Remove” tool from quick toolbar. It will delete the image from the RichTextEditor content.

Once you select the image from the local machine, the URL for the image will be generate, from there also you remove the image from the service location through the clicking of cross icon as below in the image.

RichTextEditor Image delete

Insert from Web

If you want to insert an image from online source like Google, Ping, etc., you need to enable images tool on the editor’s toolbar. By default, the images tool is open an image dialog which allows you to insert an image from online source.

Dimension

Sets the default width and height of the image when it is inserted in the RichTextEditor using Width and Height of InsertImageSettings.

Through the quickToolbar, also you can change the width and height using Change Size option. Once click into the option. The Image Size dialog will open as below. In that specify the width and height of the image in pixel.

RichTextEditor Image dimension

Caption and Alt Text

Image caption and alternative text can be specified for the inserted image in the RichTextEditor through the QuickToolbarSettings options such as Image Caption and Alternative Text.

Through the Alternative Text option, set the alternative text for the image, when the image is not upload successfully into the RichTextEditor.

By clicking the Image Caption, the image will get wrapped in an image element with a caption. Then, you can type caption content inside the RichTextEditor.

Display Position

Sets the default display for an image when it is inserted in the RichTextEditor using Display field in InsertImageSettings. It has two possible options: ‘inline’ and ‘break’.

razor
controller.cs
@{
    string value = @" <p>
    The RichTextEditor control is WYSIWYG ('what you see is what you get') editor that provides the best user experience to create and update the content.
    Users can format their content using standard toolbar commands.
</p>
<p><b> Key features:</b></p>
<ul>
    <li><p> Provides &lt; IFRAME &gt; and &lt; DIV &gt; modes </p></li>
    <li><p> Capable of handling markdown editing.</p></li>
    <li><p> Contains a modular library to load the necessary functionality on demand.</p></li>
    <li><p> Provides a fully customizable toolbar.</p></li>
    <li><p> Provides HTML view to edit the source directly for developers.</p></li>
    <li><p> Supports third - party library integration.</p></li>
    <li><p> Allows preview of modified content before saving it.</p></li>
    <li><p> Handles images, hyperlinks, video, hyperlinks, uploads, etc.</p></li>
    <li><p> Contains undo / redo manager.</p></li>
    <li><p> Creates bulleted and numbered lists.</p></li>
</ul>";
}

@Html.EJS().RichTextEditor("image").ToolbarSettings(e => e.Items((object)ViewBag.items)).Value(value).InsertImageSettings(obj => obj.Display("break")).Render()
public class HomeController : Controller
{
    public ActionResult Index()
    {
        ViewBag.items = new[] { "Image" };
        return View();
    }
}

The hyperlink itself can be an image in RichTextEditor. If the image given as hyperlink, the remove, edit and open link will be added to the quick toolbar of image as below. For further details about link, please see the link documentation.

RichTextEditor image with link

See Also