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 | |
---|---|---|---|---|---|
ClientIDMode | ClientIDMode | Gets or sets the client ID generation algorithm. |
attribute
static value
|
Static | |
DataContext | Object | Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value. The DataContext is null in client-side templates. |
attribute
bindable
|
null | |
HyperlinkTarget | String | Gets or sets target attribute on links. The default value is _blank. |
attribute
static value
bindable
|
_blank | |
ID | String | Gets or sets the control client ID within its naming container. |
attribute
static value
bindable
|
null | |
IncludeInPage | Boolean | Gets or sets whether the control is included in the DOM of the page. |
attribute
bindable
|
True | |
InnerText | String | Gets or sets the inner text of the HTML element. Note that this property can only be used on HtmlGenericControl directly and when the control does not have any children. |
attribute
static value
bindable
|
null | |
Text | String | Gets or sets the text displayed in the control. |
attribute
inner element
static value
bindable
default
|
||
Visible | Boolean | Gets or sets whether the control is visible. When set to false, `style="display: none"` will be added to this control. |
attribute
bindable
|
True | |
WrapperTagName | String |
attribute
static value
bindable
|
div |