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

  • Home
  • SEARCH
  • 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 3489460
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:23:54+00:00 2026-05-18T11:23:54+00:00

Here is a common scenario I Have these Entity User UserId UserName … UserQuestion

  • 0

Here is a common scenario
I Have these Entity
User
UserId
UserName
…

UserQuestion
UserQID
UserID
UserQuestion
UserAnswer

One user can Have many question, but one question is attached to one user.
In my example, I create 3 Empty entities (UserQuestion). Then I attache these question on the user.

In the view, for each question, answer textbox, I Use ElementAt to specify each of the UserQuestion Entity.

Why I cannot save these 3 questions

In the Controller

public ActionResult ChooseQuestion()
{
    IUserRepository repUser = new UserRepository(EntityFactory.GetEntity());
    User usr = repUser.GetUserByID(Convert.ToInt32(Session["UserID"]));
    usr.UserQuestions.Add(new UserQuestion());
    usr.UserQuestions.Add(new UserQuestion());
    usr.UserQuestions.Add(new UserQuestion());
    var ViewModel = new UsrViewModel()
                    {
                        UserInfo = usr
                    };   
    return View(ViewModel);

}

[HttpPost]
public void ChooseQuestion(User UserInfo)
{
    UpdateModel(User, "UserInfo");
    EntityFactory.GetEntity().SaveChanges();
}

In my View

<%: Html.TextBoxFor(model => model.UserInfo.UserName)%>
...
<%: Html.TextBoxFor(model => model.UserInfo.LastName%>
...
<%: Html.TextBoxFor(model => model.UserInfo.UserPassword%>
..
<h2>Question Creation</h2>
<%: Html.TextBoxFor(model => model.UserInfo.UserQuestions.ElementAt(0).UserQuestion)%>
<%: Html.TextBoxFor(model => model.UserInfo.UserQuestions.ElementAt(0).UserAnswer)%>

<%: Html.TextBoxFor(model => model.UserInfo.UserQuestions.ElementAt(1).UserQuestion)%>
<%: Html.TextBoxFor(model => model.UserInfo.UserQuestions.ElementAt(1).UserAnswer)%>

<%: Html.TextBoxFor(model => model.UserInfo.UserQuestions.ElementAt(2).UserQuestion)%>
<%: Html.TextBoxFor(model => model.UserInfo.UserQuestions.ElementAt(2).UserAnswer)%>

3

  • 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-18T11:23:55+00:00Added an answer on May 18, 2026 at 11:23 am

    Based on Phil Haack’s post you should just have sequential number in your name attribute like so:

    <%: Html.TextBoxFor(model => model.UserInfo.UserQuestions.ElementAt(0).UserQuestion, new {name="UserInfo.UserQuestion0.UserQuestion} )%>
    

    Normally the built-in HtmlHelper.TextboxFor method will do the name attribute correctly if it is in a for loop.

    As I’m not near my VS now I can’t try this magic out for myself, but you might want to check Phil’s article if you get stuck.

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

Sidebar

Related Questions

Ok, I have a complicated scenario here. I have a scrollview which scrolls horizontally
I have a number of xaml sub-workflows that I would like to reuse in
I have a couple of questions regarding a modular GWT based application framework. I
I have been trying to understand the MapReduce concept and apply it to my
If i have heterogeneous collection for which I know exactly the types i'm going
I'm aware that there probably isn't a perfect solution to my question (this sounds
Just trying to ping up some experienced Thread gurus out there...trying to learn more
To use initialization syntax like this: var contacts = new ContactList { { Dan,
I need to create a singleton that would hold lots of data for a

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.