TextView

in namespace DotVVM.BusinessPack.Controls

Converts a multi-line texts to HTML with keeping the line endings. Detects URL and e-mail addresses and converts them to hyperlinks. The text is HTML encoded to prevent XSS attacks.

Usage & Scenarios

This control can render long texts and convert them into HTML. It can detect URLs and e-mail addresses and generate hyperlinks for them. It also preserves line endings and HTML encodes the content so it is safe to render as HTML.

Sample 1: Basic Usage

The Text property specifies the text to be rendered.

<bp:TextView Text="{value: ContactInfo}" />
<bp:TextView Text="{value: Paragraphs}" />
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.TextView.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public string ContactInfo { get; set; } = "RIGANTI s.r.o.\nSokolovsk� 352/215\[email protected]\nwww.dotvvm.com";

        public string Paragraphs { get; set; } = @"TextView
                                                   Converts a multi-line texts to HTML with keeping the line endings. 
                                                   Detects URL and e-mail addresses and converts them to hyperlinks. 
                                                   The text is HTML encoded to prevent XSS attacks.

                                                   Usage & Scenarios
                                                   This control can render long texts and convert them into HTML. 
                                                   It can detect URLs and e-mail addresses and generate hyperlinks for them. 
                                                   It also preserves line endings and HTML encodes the content so it is safe to render as HTML.";
    }
}

Sample 2: Server Rendering

To render the HTML directly in the page without the need to transfer it in the viewmodel, you can use the RenderSettings.Mode to turn on the server rendering.

This helps especially the search engines to index the contents of the page. You can read more in the Server-Side HTML Generation and SEO chapter.

<bp:TextView Text="{value: ContactInfo}"
             RenderSettings.Mode="Client" />

<br />

<bp:TextView Text="{value: ContactInfo}"
             RenderSettings.Mode="Server" />
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.TextView.sample2
{
    public class ViewModel : DotvvmViewModelBase
    {
        public string ContactInfo { get; set; } = @"RIGANTI s.r.o.
                                                    Sokolovsk� 352/215
                                                    [email protected]
                                                    www.dotvvm.com";
    }
}

Sample 3: Link Target

The URLs and e-mail addresses in the text are detected automatically.

The HyperlinkTarget property specifies the target attribute value in the links generated by the control. You can use it to open the pages in a new window, for example.

<bp:TextView HyperlinkTarget="_blank">
    [email protected]
    www.riganti.cz
    https://www.riganti.cz/
    https://www.dotvvm.com/docs/latest
</bp:TextView>

Properties

Name Type Description Notes Default Value
property icon HyperlinkTarget String Gets or sets target attribute on links. The default value is _blank.
attribute
inner element
static value
bindable
default
_blank
property icon Text String Gets or sets the text displayed in the control.
attribute
inner element
static value
bindable
default
property icon WrapperTagName String
attribute
inner element
static value
bindable
default
div

HTML produced by the control