Skip to content

Views basics

Alexanderius edited this page Jul 3, 2025 · 3 revisions

Views basics

Views are classes specifically designed to generate HTML content.

Each user-created view must be derived from the View class.

Views have a limited set of accessible Simplify.Web modules: only modules useful for HTML content generation (to keep code SOLID).

Example

public class LoggedUserPanelView : View
{
    public async Task<ITemplate> Get(string userName)
    {
        var tpl = await TemplateFactory.Load("Shared/LoginPanel/LoggedUserPanel");
        tpl.Add("UserName", userName);
        return tpl;
    }
}

Accessing other views

You can access other views from a view. To do that, use the GetView<T>() method.

public class LoggedUserPanelView : View
{
    public async Task<ITemplate> Get(string userName)
    {
        var tpl = await TemplateFactory.Load("Shared/LoginPanel/LoggedUserPanel");
        tpl.Add("SomePanel", GetView<SomePanel>().Get());
        return tpl;
    }
}

<< Previous page Next page >>

Clone this wiki locally