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; } = "John Doe\nBaker Street 82\[email protected]\nwww.bakerbacon.com";
public string Paragraphs { get; set; } = @"Paragraph 1
lorem ipsum bacon ipsum bacon
lorem ipsum bacon ipsum bacon lorem ipsum bacon ipsum bacon
lorem ipsum bacon ipsum bacon lorem ipsum bacon ipsum bacon
lorem ipsum bacon ipsum bacon
Paragraph 2
lorem ipsum bacon ipsum bacon
lorem ipsum bacon ipsum bacon lorem ipsum bacon ipsum bacon";
}
}
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; } = @"John Doe
Baker Street 82
[email protected]
www.bakerbacon.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.website.com
http://website.com
https://www.google.cz/#q=dotvvm&*&spf=373
</bp:TextView>
Properties
Name | Type | Description | Notes | Default Value | |
---|---|---|---|---|---|
Attributes | Dictionary<String,Object> |
attribute
static value
|
null | ||
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. |
attribute
static value
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 unique control ID. |
attribute
static value
|
null | |
InnerText | String | Gets or sets the inner text of the HTML element. |
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. |
attribute
bindable
|
True |