Skip to content
Learn Netverks

Lesson

Step 22/36 61% through track

model-binding

Model binding

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Model binding: the syntax, APIs, and habits you need before advancing in ASP.NET.

Built-in DI is how ASP.NET Core stays testable—service lifetimes (scoped vs singleton) are interview staples.

You will apply Model binding in contexts like: Line-of-business APIs, intranets, BFF layers, and cloud-hosted services on Linux or Windows.

Write C# (top-level or Program class), click Run on server—the dev runner uses dotnet build/run on a temp net8 project (requires .NET SDK; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Model binding maps HTTP request data—route values, query strings, form fields, JSON bodies—to action parameters and complex types automatically.

Sources (priority order varies)

  • Form fields → properties by name (Emailmodel.Email)
  • Route tokens → {id} parameters
  • Query string → ?page=2
  • JSON body → API actions with [FromBody]

Complex type binding

public IActionResult Create(ProductEditModel model) {
    if (!ModelState.IsValid) return View(model);
    // save
}

[FromQuery], [FromRoute], [FromBody]

Disambiguate when names collide or for minimal APIs—be explicit in APIs with multiple primitive parameters.

Important interview questions and answers

  1. Q: Model binding vs manual Request.Form?
    A: Binding is declarative and testable; manual parsing is error-prone for complex types.
  2. Q: Nullable binding failures?
    A: Missing required non-nullable value types may fail validation—use nullable or defaults intentionally.

Self-check

  1. How does POST form data reach a view model?
  2. When use [FromBody]?

Pitfall: Binding POST data directly to EF entities enables over-posting—use view models with only the fields the form should set.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • [FromQuery] when?
  • Complex type bind?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump