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 519031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:59:55+00:00 2026-05-13T07:59:55+00:00

I have a simple form in ASP.NET MVC. I am trying to post these

  • 0

I have a simple form in ASP.NET MVC. I am trying to post these results to a controller action and I am getting strange behavior.

The view is a simple HTML table:

Picture of view

Here is part of the HTML form View:

 <form action="/Applications/UpdateSurvey" method="post"><table id=questionsTable class=questionsTable border=1>
<thead><tr><td>Name</td><td>Answer</td><td>Name Attribute(for debugging)</td></tr>         </thead><tbody>
 <tr>
 <td>Question 0:</td>

 <td><input type='checkbox' class='checkboxes' name='updater.questions[0].responseIds' value=1 >1&nbsp;&nbsp;<input type='checkbox' class='checkboxes' name='updater.questions[0].responseIds' value=2 >2&nbsp;&nbsp;<input type='checkbox' class='checkboxes' name='updater.questions[0].responseIds' value=3 >3&nbsp;&nbsp;<input type='checkbox' class='checkboxes' name='updater.questions[0].responseIds' value=4 >4&nbsp;&nbsp;<input type='checkbox' class='checkboxes' name='updater.questions[0].responseIds' value=5 >5&nbsp;&nbsp;</td>
 <td>updater.questions[0].responseIds</td>
 </tr>
 <tr>
 <td>Question 1:</td>
 <td><input type='checkbox' class='checkboxes' name='updater.questions[1].responseIds' value=1 >1&nbsp;&nbsp;<input type='checkbox' class='checkboxes' name='updater.questions[1].responseIds' value=2 >2&nbsp;&nbsp;<input type='checkbox' class='checkboxes' name='updater.questions[1].responseIds' value=3 >3&nbsp;&nbsp;<input type='checkbox' class='checkboxes' name='updater.questions[1].responseIds' value=4 >4&nbsp;&nbsp;<input type='checkbox' class='checkboxes' name='updater.questions[1].responseIds' value=5 >5&nbsp;&nbsp;</td>

 <td>updater.questions[1].responseIds</td>
 </tr>
 </tbody></table>

  <input type="submit" value="Save" />

 </form>

Binding Object:

public class SurveyUpdater
{
    public Question[] questions { get; set; }
}

public class Question
{
    public int[] responseIds { get; set; }
}

Controller Action code:

    public ActionResult UpdateSurvey(SurveyUpdater updater)
    {
        if (updater.questions == null)
        {
            //I dont understand why this is getting hit
        }
        if (updater.questions.Length != 5)
        {
            //I dont understand why this is getting hit
        }

        return View("TestSurvey");
    }

After testing, here are my observations:

  1. If I have at least one CheckBox selected on each of the questions, this works fine and in my controller updater.questions.Length == 5 and the data binds perfectly.

  2. If I don’t answer one of the questions at all, I only get an array as big as the number I skipped: -1. So if I didn’t answer Question #3, I get an array in my controller action of 2.

  3. By using the logic of #2, if I don’t answer the first question, I simply get null for updater.questions

What I want to get (and what I expected) is that:

I would always get questions with a length of 5 and in the cases where I didn’t answer one of the questions, I would simply get a 0 sized array for that index responseIds.

Is this a bug in ASP.NET MVC model binding? If not, is there anything I am missing or any way to get the desired behavior that I am looking for?

  • 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-05-13T07:59:55+00:00Added an answer on May 13, 2026 at 7:59 am

    The problem, I think, is because when no selections are chosen, the inputs are not even passed back in the request parameters. One way around this would be to have a default, hidden checkbox containing a known value that you could filter out selected initially for each question (a “not answered” checkbox, if you will). That would guarantee that you get a selection for each question and that a request parameter exists for each element in the array.

    Think about it from the perspective of what gets posted back. Only those elements that have values, have names, and aren’t disabled get posted. If not all the questions have values, then how many array items should it create? At best it can guess that the last item selected should be the size of the array — but what values should it use for any items in between? The framework can’t read your mind and, arguably, shouldn’t though providing the default value for the type might be reasonable. IMO, it would be better to just omit the value and, thus, force the developer to provide the default if desired. That seems to be what is happening.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ajax form in asp.net mvc which is as simple as this:
I have a simple form on an ASP.NET MVC site that I'm building. This
I have an ASP.Net MVC Page with a very simple form on it: One
I have a simple form which is using ASP.NET MVC 3 unobtrusive client side
I have added a text box to a simple form in ASP.NET MVC and
I have a simple in VB/ASP.NET form containing two text boxes, I am attempting
I have a pretty simple ASP.NET Web Form that looks a bit like the
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
I'm new to ASP.NET MVC and I'm trying to create a very simple blog

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.