Render a character-counting textarea¶
Emit a labeled textarea with client-side character-count data attributes. Trigger: Razor view calling the helper.
| Field | Value |
|---|---|
| Operation ID | OP-22 |
| Trigger | Razor view calling the helper |
| Inputs | Field name or lambda, optional label text, html attributes, startLength (default 0), maxLength (default 4000) |
| Outputs | MvcHtmlString — label or span markup followed by the <textarea> |
| Primary components | TextCounterHelper.TextAreaCounter and TextAreaCounterFor |
| Entry point | src/Web.Mvc/UI/Extensions/TextCounterHelper.cs |
Steps¶
TextAreaCounterForresolves the property name from the expression and delegates toTextAreaCounterwithout forwardingmaxLength, so the strongly-typed overload always applies the 4000 default (BR-52).- Compute the element
idby replacing.with_(BR-47); emitid,name,data-start-length, anddata-max-length, then merge caller attributes. - Add CSS class
js-bo-text-counter— the client-side counter hook.* - When
labelTextis blank emit a bare<span>; otherwise emit<label class="control-label" for="{id}">{labelText}</label>(BR-53). - Return the label markup concatenated with the textarea markup.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([Razor view calls TextAreaCounter])
ForOverload{Called via TextAreaCounterFor?}
Default[Apply default maxLength 4000]
Id[Compute sanitized element id]
Label{labelText blank?}
Span[Emit bare span]
LabelEl[Emit label element]
Textarea[Emit textarea]
EndOk([Return combined markup])
Start --> ForOverload
ForOverload -->|Yes| Default
ForOverload -->|No| Id
Default --> Id
Id --> Label
Label -->|Yes| Span
Label -->|No| LabelEl
Span --> Textarea
LabelEl --> Textarea
Textarea --> EndOk
Failure and edge-case behavior¶
- No unexpected failure paths beyond argument-guard exceptions and delegated dependency behavior were identified for this operation.
Related documentation¶
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¶
src/Web.Mvc/UI/Extensions/TextCounterHelper.cs