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

The Archive Base Latest Questions

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

I am trying to create an online survey. I have a View where a

  • 0

I am trying to create an online survey.

I have a View where a user can create a Multiple Choice question with as many answer possibilities as the user wishes. Each answer possibility is supposed to have text boxes which represents the following properties:

[Multiple_Choice_Question]
int choice_number { get; set; } // The order in which the MCQ answer possibility is shown
int choice_wording { get; set; } // The MCQ answer possibility
string help_text { get; set; } // help_text if the user doesnt understand the answer possibility

How should my ViewModel look like, when i dont know how many answer possibilities the user wants?

Thanks

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

    Use javascript and the JSON model binding in MVC3 to help you here.

    On the client side create a javascript “object” that matches your server side object

    function MultipleChoiceQuestion(choice_number, choice_wording, help_text)
    {
        this.ChoiceNumber = choice_number;
        this.ChoiceWording = choice_wording;
        this.HelpText = help_text;
    }
    

    Then use javascript to iterate and parse through the DOM to get the variable number of answers.

    psuedo-code…

    var ListOfQuestions = [];
    foreach(some dom elements)
    {
        var cn = dom.choiceNumber;
        var cw = dom.choiceWording;
        var ht = dom.helpText;
    
        var question = new MultipleChoiceQuestion(cn, cw, ht);
        ListOfQuestions.push(question);
    
    }
    

    Post this with ajax. One downside to this method is that you have to use ajax.

    $.ajax({
       url:"/yoursite/controller/action",
       type:"POST",
       data: JSON.stringify(ListOfQuestions),
       dataType: 'json',
       contentType: 'application/json, charset=utf-8',
       success: function(data){},
       error: function(){}
    
    });
    

    Then on the server side you have your question class as you’ve already defined it(your property names must match the client side property names), and a container class…

    public class QuestionContainer()
    {
        public List<MultipleChoiceQuestion> Questions {get; set;
    }
    

    and your Action takes this as a parameter

    public ActionResult Create(QuestionContainer questions)
    {
    
        ...
    }
    

    Phil Haack did an article about this, but before the MVC3 binding was released. It’s easier now than what he wrote about.

    http://haacked.com/archive/2010/04/15/sending-json-to-an-asp-net-mvc-action-method-argument.aspx

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

Sidebar

Related Questions

I'm trying to create am online application for some job postings we have at
I am trying to create a music player/centre online. I have a player that
I am trying to create a online test application,and invoking question with options on
I have been trying to create a Ruby program that will be running online
I am trying to create a simple online calculator that can run basic calculations
I am trying to create sliding images effect: Online demo link text . The
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Trying to create a black line in my view to separate text blocks but
Trying to create a macro which can be used for print debug messages when
I'm trying to create an online calculator as a means to help me learn

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.