Skip to content

Views basics

Alexanderius edited this page Sep 15, 2019 · 1 revision

Views basics

Views is a classes specifically designed to generated HTML content.

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

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

Example

public class LoggedUserPanelView : View
{
    public ITemplate Get(string userName)
    {
        var tpl = await TemplateFactory.Load("Shared/LoginPanel/LoggedUserPanel");

        tpl.Add("UserName", userName);

        return tpl;
    }
}

Accessing a views

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

public class LoggedUserPanelView : View
{
    public 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