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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:16:50+00:00 2026-05-30T07:16:50+00:00

I have been reading hundreds of posts on ASP.NET blogs and questions on StackOverflow

  • 0

I have been reading hundreds of posts on ASP.NET blogs and questions on StackOverflow but I can’t find a solution to this (apparently) simple problem. Here is a simplified version:

Question Class

public class Question
{
    public int QuestionId { get; set; }
    public string QuestionBody { get; set; }
    public List<string> Answers { get; set; }
}

I have a simple form for the creation of a Question object. I know there isn’t an automatic EditorFor for collections, so I have tried with:

In my form:

<div class="editor-field">
     @Html.TextBox("Answers")
     @Html.TextBox("Answers")
     @Html.TextBox("Answers")
</div>

In my controller:

public ActionResult Create(Question question, List<string> Answers)
 ...

The answers are correctly passed but they are not being binded to my model!

Question #1: Does exist a way to automatically tie this List of strings to the List of strings contained in my Question model?

Then I tried to “force” this List to be the List in my model, doing:

   question.Answers = Answers;
   db.Questions.Add(question);
   db.SaveChanges();

But my collection is always being passed as empty. I think this is due to the ASP.NET MVC model binding and validation.

So, Question #2: Does exist a way to “modify” my question object just before it is saved to the database with db.SaveChanges() ?

Thank you.

  • 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-30T07:16:52+00:00Added an answer on May 30, 2026 at 7:16 am

    you will need to create an editor template for your list see here:

    Editor Templates for List<string>

    or you can simply put

    <div class="editor-field">
         @Html.TextArea("Answers")
    </div>
    

    then the returning info will arrive as string and you can then split that string by line and make a list of it using Linq extensions:

    public ActionResult Create(Question question, string answers)
    {
        var answerList = answers.Split('\n').ToList();
         question.Answers = answerList;
         db.Questions.Add(question);
        db.SaveChanges();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been reading over a lot of questions, but cant seem to find
I have been reading so many topics here about this, but I could not
I have been reading through lots of Q&A everywhere and these stackoverflow posts seem
I have been reading the doc and searching but cannot seem to find a
I have been reading a lot of posts on this site regarding the usage
I have been reading a lot about openFrameworks and Processing, But still can't make
I have been reading lots of posts and am confused as to why this
I have been reading about branch prediction but the only implementation I find are
I have been reading this blog post and this stack overflow post but I
I have been reading through this similar question and find myself less than satisfied

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.