Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8193141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:22:52+00:00 2026-06-07T04:22:52+00:00

I want to make a day of the week checkbox using a viewModel. Everything

  • 0

I want to make a day of the week checkbox using a viewModel. Everything is ok on the View, but, if I click submit to save changes, weeklySchedule within my httppost method is null.

Why is weeklySchedule null? How would I send the selected checkbox value to my HttPost action? Any advice would help.

enter image description here

Model:

public class Settings
{
    public class WeeklySetting
    {
        public string DisplayName { get; set; }
        public string Value { get; set; }
        public bool IsChecked { get; set; }
    }
}

View Model:

public class ViewModels
{
    public class Weekly
    {
        public List<Settings.WeeklySetting> Settings { get; set; }
    }
}


public ActionResult CreateWeekly()
   {
       var model = new ViewModels.Weekly
       {
             Settings = new[] 
             {
             new Settings.WeeklySetting{ DisplayName="Monday", Value="MON", IsChecked=false},
             new Settings.WeeklySetting{ DisplayName="Tuesday", Value="TUE", IsChecked=false},
             new Settings.WeeklySetting{ DisplayName="Wednesday", Value="WED", IsChecked=false},
             new Settings.WeeklySetting{ DisplayName="Thursday", Value="THU", IsChecked=false},
             new Settings.WeeklySetting{ DisplayName="Friday", Value="FRI", IsChecked=false},
             new Settings.WeeklySetting{ DisplayName="Saturday", Value="SAT", IsChecked=false},
              new Settings.WeeklySetting{ DisplayName="Sunday", Value="SUN", IsChecked=false},
            }.ToList()
       };
           return View(model);

   }
   [HttpPost]
   public ActionResult CreateWeekly(string submitButton, ViewModels.Weekly weeklySchedule)
   {

    //Do something
       return View("CreateWeekly", weeklySchedule);
   } 

View:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MyProject.Controllers.ViewModels.Weekly>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> CreateWeekly </asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<% using (Html.BeginForm()) { %>

  &#60;div&#62;
  &#60;%foreach (var item in Model.Settings)
    {%&#62;

        &#60;%:Html.CheckBoxFor(q=&#62;item.IsChecked) %&#62;
        &#60;%:Html.LabelFor(q=&#62;item.IsChecked,item.DisplayName) %&#62;
        &#60;%:Html.HiddenFor(q=&#62;item.Value) %&#62;
   &#60;% } %&#62;

  &#60;/div&#62;
&#60;br /&#62;
   &#60;input value="GenerateForWeekly" name="submitButton" type="submit" /&#62;
      &#60;%} %&#62;

</asp:Content>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:22:53+00:00Added an answer on June 7, 2026 at 4:22 am

    Model binding doesn’t work very nicely when you start using foreach() { } loops in your view. If you use an EditorTemplate for WeeklySetting you’ll find it works much better as it sorts out all the indices for you.

    E.g. (this is MVC3 Razor view syntax)

    (1) Create an editor template for WeeklySetting:

    @model Settings.WeeklySetting
    @Html.CheckBoxFor(m => m.IsChecked)
    @Html.LabelFor(m => m.IsChecked,Model.DisplayName)
    @Html.HiddenFor(m => m.DisplayName)
    @Html.HiddenFor(m => m.Value)
    

    (2) Render in your view with an EditorFor (no foreach):

    @using (Html.BeginForm())
    {
        <div>
            @Html.EditorFor(m => m.Settings)
        </div>
        <br />
        <input value="GenerateForWeekly" name="submitButton" type="submit" />
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a service which can set wallpaper every day on the
I want make datetimepicker in my project. Using jquery how it is possible? I
I am traversing a HTML document using javascript DOM. I want make a list
I want to make the date to change one day every n seconds, like
Good day everybody, I want to make an if conditional with the following aim:
If you choose to view a week or day the left column will by
i've been struggeling with this all day now I want to make an API
Good day! I'm making nondeterministic finite automata with c++. I want to make a
Good day users, I want to make an form with an input field, and
I have this problem where i want to make 7 dropdowns for each day

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.