---
title: clsModelBase
summary: API reference for clsModelBase.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.MVC
reference_type: package
---

# clsModelBase

`clsModelBase` is the screen model base class every SAIF screen's concrete model derives from. It holds the screen's `clsContext` and user `clsPreferences`, defines the validate-then-write contract (`ValidateData` → `WriteData`, exposed publicly as `Write`) that [Validate and write the model](../../operations/validate-and-write-model.md) documents, performs one-time initialization and preference loading through `Pre_Init` (called from `clsControllerBase.Initialize`), and supplies a small set of protected string/date validation helpers reused by derived screens' own `ValidateData` implementations.

## Purpose
- Gates every model write behind the derived screen's own validation, so `WriteData` is only ever called when `ValidateData` returns `True` ([BR-MVC-029](../../business-rules.md#br-mvc-029-a-model-is-written-only-after-its-own-validation-succeeds)).
- Performs one-time model initialization and user-preference loading on first use per instance, via `Pre_Init` ([BR-MVC-016](../../business-rules.md#br-mvc-016-a-model-initializes-exactly-once-per-instance)).
- Carries the screen's `clsContext`, giving every model access to the established security principal, cross-application context values, and well-known context keys (`claimId`, `policyNum`, etc.).
- Provides reusable string/number/date validation predicates so derived `ValidateData` implementations do not each reimplement basic input checks.

## Context
- Namespace: `SAIF.Presentation.Web.MVC`*
- Assembly/package: `SAIF.Presentation.Web.MVC`

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| `New` | `Public Sub New()` | Constructs the model with a fresh `clsContext` instance |
| `Context` | `Public Property Context() As clsContext` | The screen's context bag — security principal, well-known claim/policy fields, and cross-application context values |
| `LastError` | `Public Property LastError() As String` | Free-form error text a derived model can set for the calling controller/screen to surface |
| `Preferences` | `Public ReadOnly Property Preferences() As clsPreferences` | The user's preferences, loaded once by `Pre_Init` for the model's application/user pair |
| `SecurityPrincipal` | `Public Property SecurityPrincipal() As clsSecurityPrincipal` (marked `Obsolete`, favoring `Context.SecurityPrincipal`) | Legacy pass-through to `Context.SecurityPrincipal`, retained for backward compatibility |
| `Write` | `Protected Friend Function Write() As Boolean` | Calls the derived `ValidateData()`; only when it returns `True` does it call `WriteData()` and return its result, otherwise returns `False` without writing ([BR-MVC-029](../../business-rules.md#br-mvc-029-a-model-is-written-only-after-its-own-validation-succeeds)) |
| `ValidateData` | `Protected Friend MustOverride Function ValidateData() As Boolean` | Derived-class hook that validates the model's current state before a write is attempted |
| `WriteData` | `Protected Friend MustOverride Function WriteData() As Boolean` | Derived-class hook that persists the model's current state; only invoked after `ValidateData` succeeds |
| `Initialize` | `Protected Friend Overridable Sub Initialize()` | Derived-class hook called exactly once per model instance, from `Pre_Init`; default implementation is a no-op |
| `UnInitialize` | `Protected Friend Overridable Sub UnInitialize()` | Derived-class hook for model teardown; default implementation is a no-op |
| `IsValidString` | `Protected Function IsValidString(ByVal Value As String) As Boolean` | `True` unless the value is `Nothing` or, after trimming, empty |
| `IsValidNumber` | `Protected Function IsValidNumber(ByVal Value As String) As Boolean` | `True` when the value is a valid non-empty string and `IsNumeric` |
| `IsValidDate` | `Protected Function IsValidDate(ByVal Value As String) As Boolean` | `True` when the value is a valid non-empty string and `IsDate` |
| `IsValidFutureDate` (string) | `Protected Function IsValidFutureDate(ByVal Value As String) As Boolean` | `True` when the value is a valid date string strictly later than today (compared by short date) |
| `IsValidFutureDate` (date) | `Protected Function IsValidFutureDate(ByVal Value As Date) As Boolean` | `True` when the date value is strictly later than today (compared by short date) |

## Behavioral notes
- `Pre_Init` (`Friend`, called by `clsControllerBase.Initialize` as part of [Initialize a request](../../operations/initialize-request.md)) is idempotent per instance: it checks an internal `m_Inited` flag before calling `Initialize()` and constructing `clsPreferences`, so it only runs once even if invoked multiple times against the same model instance ([BR-MVC-016](../../business-rules.md#br-mvc-016-a-model-initializes-exactly-once-per-instance)).
- `Preferences` is constructed with `Context.SecurityPrincipal.UserName().ToString` and the application name, so it is only safely accessible after `SecurityPrincipal` has been established (i.e., after `Pre_Init` has run following a successful `SecurityCheck`).

## Constraints and usage notes
- `clsModelBase` is `MustInherit` — every screen supplies its own concrete model subclass and overrides `ValidateData` and `WriteData` (both `MustOverride`).
- `SecurityPrincipal` is marked `Obsolete`; new code should read/write `Context.SecurityPrincipal` directly.

> **Note:** Statements marked with `*` were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.

## Sources
- SAIF.Presentation.Web.MVC/clsModelBase.vb
