---
title: Validate and write the model
summary: Gates every model write behind the derived screen's own validation, so data is never persisted unless the screen confirms it is valid.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.MVC
reference_type: package
operation_id: OP-MVC-13
trigger: clsControllerBase.Write, typically from a Save button handler
---

# Validate and write the model

The single choke point through which every controller-initiated save passes: the model is never written unless the derived screen's own validation logic confirms the data is valid.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-MVC-13 |
| **Trigger** | `clsControllerBase.Write`, typically from a Save button handler |
| **Inputs** | Current model state |
| **Outputs** | Boolean success; model persisted only when validation passes |
| **Primary components** | `clsModelBase.Write` |
| **Entry point** | SAIF.Presentation.Web.MVC/clsModelBase.vb |

## Steps

1. Call the derived `ValidateData()` ([BR-MVC-029](../business-rules.md#br-mvc-029-a-model-is-written-only-after-its-own-validation-succeeds)).
2. Only when validation returns `True`, call the derived `WriteData()` and return its result.
   - If validation returns `False`: return `False` immediately without calling `WriteData()` — no write is attempted.
3. `clsControllerBase.Write` simply delegates to this operation, so every controller-initiated save passes through the same validation gate.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start([clsModelBase.Write]) --> S1[Call derived ValidateData]
	S1 --> D1{Validation returned True?}
	D1 -->|No| EndFail([Return False - no write attempted])
	D1 -->|Yes| S2[Call derived WriteData]
	S2 --> EndOk([Return WriteData result])
```

## Failure and edge-case behavior
- A screen that always returns `True` from `ValidateData` effectively disables this safeguard — the base class enforces the ordering, not the validation content itself.
- `WriteData`'s own exceptions are not caught here; they propagate to the caller (typically surfacing through [Page error processing](page-error-processing.md)).

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

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