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

# clsModelBase

`clsModelBase` is the abstract Model-layer contract of this library's WebForms MVC retrofit. It owns a `clsContext` (cross-application state) and a `clsPreferences` (user/application preference lookup, from `SAIF.Presentation`), defines the `ValidateData`/`WriteData` template method behind [BR-MVC-006](../../business-rules.md#br-mvc-006-write-requires-prior-validation), and provides shared input-validation helper methods used by concrete models across the SAIF web application suite.

## Purpose
- Guarantees that persistence (`WriteData`) never runs without a prior successful validation (`ValidateData`) via the `Write()` template method ([BR-MVC-006](../../business-rules.md#br-mvc-006-write-requires-prior-validation)).
- Lazily initializes the concrete model exactly once per session (`Pre_Init`) and loads the current user's `clsPreferences` for the model's application.
- Supplies reusable string/number/date/future-date validation helpers so concrete models do not need to reimplement basic input checks.

## Context
- Namespace: `SAIF.Presentation.Web.MVC`
- Assembly/package: `SAIF.BOF.Presentation.Web.Infragistics103` (source-bundled)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| `Context` | `Public Property Context() As clsContext` | The cross-application context bag for this model instance; initialized to a new `clsContext` in the constructor. |
| `LastError` | `Public Property LastError() As String` | Holds the most recent error message set by the concrete model, e.g., during validation failures. |
| `Preferences` | `Public ReadOnly Property Preferences() As clsPreferences` | The current user's preferences for this model's application, populated during `Pre_Init()`; `Nothing` until `Pre_Init()` has run. |
| `SecurityPrincipal` | `Public Property SecurityPrincipal() As clsSecurityPrincipal` (marked `Obsolete`) | Forwards to `Context.SecurityPrincipal`; deprecated in favor of accessing `Context.SecurityPrincipal` directly. |
| `ValidateData` | `Protected Friend MustOverride Function ValidateData() As Boolean` | Abstract hook the concrete model implements to validate its current in-memory state before a write; gates whether `WriteData()` runs ([BR-MVC-006](../../business-rules.md#br-mvc-006-write-requires-prior-validation)). |
| `WriteData` | `Protected Friend MustOverride Function WriteData() As Boolean` | Abstract hook the concrete model implements to persist its current in-memory state; only invoked by `Write()` when `ValidateData()` returns `True`. |
| `Initialize` | `Protected Friend Overridable Sub Initialize()` | Overridable hook for one-time concrete-model setup, invoked exactly once per model instance from `Pre_Init()`; no-op by default. |
| `UnInitialize` | `Protected Friend Overridable Sub UnInitialize()` | Overridable hook for concrete-model teardown; no-op by default. |
| `New()` | `Public Sub New()` | Initializes `Context` to a new `clsContext` instance. |
| `Write` | `Protected Friend Function Write() As Boolean` | Template method: calls `ValidateData()`, and only if it returns `True`, calls `WriteData()`; returns the eventual result or `False` if validation failed ([BR-MVC-006](../../business-rules.md#br-mvc-006-write-requires-prior-validation)). |
| `IsValidString` | `Protected Function IsValidString(ByVal Value As String) As Boolean` | Returns `False` if `Value` is `Nothing` or, after trimming, an empty string; otherwise `True`. |
| `IsValidNumber` | `Protected Function IsValidNumber(ByVal Value As String) As Boolean` | Returns `True` only if `Value` passes `IsValidString` and `IsNumeric(Value)`. |
| `IsValidDate` | `Protected Function IsValidDate(ByVal Value As String) As Boolean` | Returns `True` only if `Value` passes `IsValidString` and `IsDate(Value)`. |
| `IsValidFutureDate` (String overload) | `Protected Function IsValidFutureDate(ByVal Value As String) As Boolean` | Returns `True` only if `Value` is a valid, non-empty date strictly later than today's date (compared by short-date string). |
| `IsValidFutureDate` (Date overload) | `Protected Function IsValidFutureDate(ByVal Value As Date) As Boolean` | Returns `True` only if `Value` is strictly later than today's date (compared by short-date string). |

## Behavioral notes
- `Pre_Init()` is `Friend`-scoped and marked `<DebuggerStepThrough()>`; it is invoked by `clsControllerBase.Initialize()` and `Navigate2`, not called directly by consuming pages.
- `Preferences` is constructed using `Context.SecurityPrincipal.UserName()` and `Context.ApplicationName` — if `Pre_Init()` runs before `SecurityCheck()` has populated `SecurityPrincipal`, this would raise a null-reference error; in practice `clsControllerBase.Initialize()` always calls `SecurityCheck()` before `Model.Pre_Init()`.*

## Constraints and usage notes
- `ValidateData`/`WriteData`/`Retrieve`-style concrete behavior is entirely defined by consuming applications; this library provides only the ordering contract and validation helpers.
- `IsValidFutureDate` compares dates using `ToShortDateString`, meaning time-of-day components are ignored — "today" itself is not considered a future date.

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

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