How to do it...

  1. Let's see how nested types are handled by ModelBinding:
public class Product{  public int Id { get; set; }  public int Name { get; set; }  public decimal Price { get; set; }  public Category Category   {    get;    set;   }}public class Category{  public int Id {     get;     set;   }  public int Name   {     get;     set;  }}@model R2.Models.Product<form asp-action="Create" method="post">  <div class="form-group">    <label asp-for="Id"></label>    <input asp-for="Id" class="form-control" />  </div>  <div class="form-group">    <label asp-for="Name"></label>    <input asp-for="Name" class="form-control" />  </div>  <div class="form-group">    <label asp-for="Price"></label>    <input asp-for="Price" class="form-control" />  </div>  <div class="form-group">    <label asp-for

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.