---
title: Model write pipeline
summary: Validates model state before allowing it to be persisted.
status: draft
owner: SAIF Documentation Team
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.MVC
reference_type: package
operation_id: OP-MVC-004
trigger: Explicit controller/page call to Write() (typically a save postback)
---

# Model write pipeline

`clsModelBase.Write()` is a template method that guarantees `WriteData()` is only invoked when `ValidateData()` succeeds. Both methods are abstract (`MustOverride`) and implemented entirely by the concrete model in each consuming application — this library only enforces the ordering contract.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-MVC-004 |
| **Trigger** | Explicit call to `clsControllerBase.Write()` (which calls `Model.Write()`), typically on a save postback |
| **Inputs** | Model's in-memory state, populated by the concrete `Retrieve` implementation |
| **Outputs** | Boolean success |
| **Primary components** | `clsModelBase.Write`, `clsControllerBase.Write` |
| **Entry point** | SAIF.Presentation.Web.MVC\clsModelBase.vb |

## Steps

1. `clsControllerBase.Write()` calls `Model.Write()`.
2. `clsModelBase.Write()` calls the abstract `ValidateData()` ([BR-MVC-006](../business-rules.md#br-mvc-006-write-requires-prior-validation)).
   - If `ValidateData()` returns `True`: call the abstract `WriteData()` and return its result.
   - If `ValidateData()` returns `False`: return `False` without calling `WriteData()`.
   - Both `ValidateData()` and `WriteData()` are implemented by the concrete model in the consuming application — no further step tracing is possible from this library alone.

## Process flow

```mermaid
flowchart TD
	Start([controller.Write called]) --> ModelWrite[Model.Write]
	ModelWrite --> Validate[ValidateData - concrete model]
	Validate --> Valid{Returns True?}
	Valid -->|Yes| WriteData[WriteData - concrete model]
	Valid -->|No| Fail([Return False, no persistence])
	WriteData --> Success([Return WriteData result])
```

## Failure and edge-case behavior
- No default validation logic exists in this library; if a consuming model's `ValidateData()` always returns `True`, this pipeline provides no actual data-integrity protection on its own.
- Exceptions thrown by `ValidateData()` or `WriteData()` propagate up to `ViewPageBase.Page_Error` → [Error handling](error-handling.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
