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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:13:43+00:00 2026-06-12T21:13:43+00:00

I am developing a page for rating questions. In the view, I have a

  • 0

I am developing a page for rating questions.

In the view, I have a list of questions and 5 radio buttons in front of each one of them.

<input name="evalId" type="hidden" value="@Model.Evaluation.EvalId" />
foreach (var question in questionList)
{
     <input name="questionId" type="hidden" value="@question.QuestionId" />
     <div class="row_star" style="border-bottom : 0 none; background: none;">
       @if (!String.IsNullOrEmpty(question.QuestionTitre))
       {
         <p>@question.QuestionTitre.TrimEnd()</p>
       }

       @* here goes the code for 5 radio buttons*@
}

Now, in my controller I want to be able to know which radio button was checked for each question.

How can I do that ?

Here is my ViewModel

public class EvaluationViewModel
{
    /// <summary>
    /// 
    /// </summary>
    public EvalEvaluation Evaluation
    {
        get;
        set;
    }

    /// <summary>
    /// 
    /// </summary>
    public Dictionary<EvalQuizz, List<EvalQuestion>> EvalQuizzQuestionList
    {
        get;
        set;
    }
}
  • 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-06-12T21:13:45+00:00Added an answer on June 12, 2026 at 9:13 pm

    Assuming your ViewModel is like this

    public class Question
    {
        public int ID { set; get; }
        public string QuestionText { set; get; }
        public List<Answer> Answers { set; get; }
        public int SelectedAnswer { set; get; }
        public Question()
        {
            Answers = new List<Answer>();
        }
    }
    public class Answer
    {
        public int ID { set; get; }
        public string AnswerText { set; get; }
    }
    public class Evaluation
    {
        public List<Question> Questions { set; get; }
        public Evaluation()
        {
            Questions = new List<Question>();
        }
    }
    

    And in your GET action method, you will return the viewmodel back to the view with some questions and answers filled in it. In the code below I’ve hardcoded the questions and answers. You may get it from your Repositary/Service layer.

    public ActionResult Index()
    {
        var evalVM = new Evaluation();
    
        //the below is hardcoded for DEMO. you may get the data from some  
        //other place and set the questions and answers
    
        var q1=new Question { ID=1, QuestionText="What is your favourite language"};
        q1.Answers.Add(new Answer{ ID=12, AnswerText="PHP"});
        q1.Answers.Add(new Answer{ ID=13, AnswerText="ASP.NET"});
        q1.Answers.Add(new Answer { ID = 14, AnswerText = "Java" });
        evalVM.Questions.Add(q1);
    
        var q2=new Question { ID=2, QuestionText="What is your favourite DB"};
        q2.Answers.Add(new Answer{ ID=16, AnswerText="SQL Server"});
        q2.Answers.Add(new Answer{ ID=17, AnswerText="MySQL"});
        q2.Answers.Add(new Answer { ID=18, AnswerText = "Oracle" });
        evalVM.Questions.Add(q2);
    
        return View(evalVM);
    }
    

    Now we will create an Editor Template to render our Question. so go to your View Folder and create a folder called EditorTemplates under the folder with your current controller name.
    Add a view to the EditorTemplates folder and give the same name as the class name we want to represent. ie : Question.cshtml
    enter image description here

    Now put this code in the editor tempalte

    @model YourNameSpace.Question
    <div>
        @Html.HiddenFor(x=>x.ID)
        @Model.QuestionText
        @foreach (var a in Model.Answers)
        {
            <p>
            @Html.RadioButtonFor(b=>b.SelectedAnswer,a.ID)  @a.AnswerText 
            </p>
        }
    </div>
    

    Now go to our main view and use EditorTemplate html helper method to bring the EditorTemplate we created to the main view.

    @model YourNameSpace.Evaluation
    <h2>Index</h2>
    @using (Html.BeginForm())
    {
        @Html.EditorFor(x=>x.Questions)
        <input type="submit" />
    }
    

    Now in your HttpPost you can check the posted model and get the selected radio button (SelectedAnswer) value there

    [HttpPost]
    public ActionResult Index(Evaluation model)
    {
        if (ModelState.IsValid)
        {
            foreach (var q in model.Questions)
            {
                var qId = q.ID;
                var selectedAnswer = q.SelectedAnswer;
                //Save
    
            }
            return RedirectToAction("ThankYou"); //PRG Pattern
        }
        //reload questions
        return View(model);
    }
    

    If you use visual studio breakpoints, you can see the values posted. Thanks to MVC Model binding 🙂
    enter image description here

    You can read about it and download a working sample here.

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

Sidebar

Related Questions

I am developing a web page with rating mechanism, so I need two buttons
I am developing a web page with rating mechanism, so I need two buttons
I am developing a page in which i have to show video with its
I'm developing a single-page view for a resource that contains multiple nested resources. Using
I am developing an events page using jquery mobile. I have a stylish way
I am developing a aspx page. In the page I have three dropdownlists and
I have run into an interesting problem. I am currently developing php page and
I am developing a web page in which a rad grid displays the list
I have a question, I am developing a web page and I communicate with
I am developing a page that needs to be able to view on 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.