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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:32:45+00:00 2026-05-24T01:32:45+00:00

My code: public ActionResult Index() { IndexViewModel indexViewModel = new IndexViewModel(); indexViewModel.Questions = GetQuestions();

  • 0

My code:

public ActionResult Index()
{
    IndexViewModel indexViewModel = new IndexViewModel();
    indexViewModel.Questions = GetQuestions();

    //Look here, I need to associate a answer for each question, i make a array with the number of questions, this seems a good idea?
    indexViewModel.Answers = new Answer[indexViewModel.Questions.Count];

    return View(indexViewModel);
}

[HttpPost]
public ActionResult Index(IndexViewModel indexViewModel)
{
    if (ModelState.IsValid)
    {
        //The problem is here:
        //The **Questions** property in IndexViewModel comes empty
        //and I need to associate Questions and Answers

        ...

        context.SaveChanges();

        return RedirectToAction("Index");
    } else
    {
        indexViewModel.Questions = GetQuestions();
        indexViewModel.Answers = new Answer[indexViewModel.Questions.Count];

        return View(indexViewModel);
    }
}

private IList<Question> GetQuestions()
{
    return context.Question.ToList();
}

The problem is in code comments. Thanks.

Update:

My HTML:

@using (Html.BeginForm()) {
<fieldset>
    @Html.ValidationSummary(false, "Fix the erros:")

    @for (int i = 0; i < Model.Questions.Count; i++)
    {
        <div class="editor-label">
            @Html.DisplayFor(model => model.Questions[i].Description)
        </div>
        <div class="editor-field">
            @Html.LabelFor(model => model.Answers[i].Score)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Answers[i].Score)
        </div>
    }

    <p>
        <input type="submit" value="Send" />
    </p>
</fieldset>
}
  • 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-24T01:32:46+00:00Added an answer on May 24, 2026 at 1:32 am

    probably the format you are rendering the view is not compliant to the default binder:

    http://www.hanselman.com/blog/ASPNETWireFormatForModelBindingToArraysListsCollectionsDictionaries.aspx

    If you can’t change the format of the HTML you have to create your own custom binder

    ASP.NET MVC – Custom model binder able to process arrays

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

Sidebar

Related Questions

here is my code public ActionResult Index() { ViewBag.Message = Welcome to ASP.NET MVC!;
I have this code: EmployeeEntities storeDB = new EmployeeEntities(); public ActionResult Index() { var
I have the following code: public ActionResult SomeAction() { return new JsonpResult { Data
I'll make it simple, here's the code I've got. public ActionResult DeleteNonCIStaffUser(int id) {
If in my controller: public ActionResult Index() { //no code implied return View; }
I'm generating a CSV file from the following code public ActionResult Index() { var
Consider the following code: public ActionResult Index(String URLQuery = http://www.google.com) { HttpWebRequest webRequest; HttpWebResponse
I have this code: public ActionResult Index() { MembershipUser currentUser = Membership.GetUser(); Guid UserId
I'm passing from the controller an array generated by the next code: public ActionResult
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public

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.