title: How do you bind a checkbox in .net core razor pages?
body: <p>How do you bind a checkbox in .net core razor pages?
  I'm currently having problems where the checkbox value isn't coming back when I submit the form (using post method).</p>
  <p>Below is my code.</p>
  <p>domain classes:</p>
  <pre><code>public class Restaurant
  {
      public int Id { get; set; }
      [Required, StringLength(80)]
      public string Name { get; set; }
      public Meals MealsServed { get; set; }
  
  }
  public class Meals
  {
      public int Id { get; set; }
      public bool Breakfast { get; set; }
      public bool Lunch { get; set; }
      public bool Dinner { get; set; }
  }
  </code></pre>
  <p>from page model:</p>
  <pre><code>    [BindProperty]
      public Restaurant Restaurant{ get; set; }
      public EditModel(IRestaurantData restaurantData, IHtmlHelper htmlHelper)
      {
          this.restaurantData = restaurantData;
          this.htmlHelper = htmlHelper;
      }
      public IActionResult OnGet(int? restaurantId)
      {
  
              Restaurant = restaurantData.GetById(restaurantId.Value);
              Restaurant.MealsServed.Breakfast = true;
              return Page();
      }
  
      public IActionResult OnPost()
      {
          if (!ModelState.IsValid)
          {
              return Page();
          }
          restaurantData.Update(Restaurant);
          restaurantData.Commit();
          TempData[&quot;Message&quot;] = &quot;Restaurant Saved&quot;;
          return RedirectToPage(&quot;./Detail&quot;, new { restaurantId = Restaurant.Id });
  
      }
  </code></pre>
  <p>from razor page:</p>
  <pre><code>&lt;form method=&quot;post&quot;&gt;
  &lt;input type=&quot;hidden&quot; asp-for=&quot;Restaurant.Id&quot; /&gt;
  &lt;div class=&quot;form-group&quot;&gt;
      &lt;label asp-for=&quot;Restaurant.Name&quot;&gt;&lt;/label&gt;
      &lt;input asp-for=&quot;Restaurant.Name&quot; class=&quot;form-control&quot; /&gt;
      &lt;span class=&quot;text-danger&quot; asp-validation-for=&quot;Restaurant.Name&quot;&gt;&lt;/span&gt;
  &lt;/div&gt;
  
  &lt;div class=&quot;form-group&quot;&gt;
      &lt;input asp-for=&quot;Restaurant.MealsServed.Lunch&quot; /&gt;
      &lt;label asp-for=&quot;Restaurant.MealsServed.Lunch&quot;&gt; &lt;/label&gt;
  &lt;/div&gt;
  
  &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Save&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>