Fix MVC 5 Read-Only Collection Properties That Never Bind

An action receives no edited rows even though the network request contains them.

Applies to ASP.NET MVC 5 on .NET Framework. Use a staging or development copy to reproduce the behavior and inspect the actual response before changing production.

Diagnostic flowchart

Does the input model expose a writable collection? Yes: Review the input shape. No: Give the input a mutable contract. Then run the regression checks.

Isolate the cause

Does the input model expose a writable collection?

  • Yes. Examine the prefixes, element keys and binding errors before modifying the input class.
  • No. A computed getter or uninitialized read-only collection can prevent the binder from building the required result.

Apply the fix

Use a settable list of DTOs for the form and validate posted row IDs before applying domain changes. Keep read-only rendering models separate.

public sealed class OrderRowsInput {
    public List<OrderRowInput> Rows { get; set; } = new List<OrderRowInput>();
}

Verify the result

  • Expected path. Submit two valid rows and confirm both appear in the input model.
  • Regression check. Submit invalid row details and check the action leaves the persistent collection untouched.

Microsoft reference for binding edge cases · ASP.NET PB Tutorial Index

Comments