locked
mvc5 tried to grouped radio button from a list RRS feed

  • Question

  • User1694748171 posted

    I tried to created a quiz web application that contain 60 questions. each question had a 4 answered. when I tried to select the second question it de selected the first radio button an so on. Its all group to one single group that caused this problem so I need help please. 

    my controller==>

    public ActionResult Index(string StudentName)
    {
    var model = (from q in db.Exam_Questions
    join A in db.Exam_Answers on q.QuestionId equals A.QuestionId
    select new Student_Exam_ViewModel
    {
    GeneralQuestions = new List<Question>
    {
    new Question
    {
    QuestionName = q.QuestionName,

    PossibleAnswers =
    new[]
    {
    new PossibleAnswer { AnswerId = A.AnswerId, Answer = A.Answer_Option_1},
    new PossibleAnswer { AnswerId = A.AnswerId, Answer = A.Answer_Option_2},
    new PossibleAnswer { AnswerId = A.AnswerId, Answer = A.Answer_Option_3},
    new PossibleAnswer { AnswerId = A.AnswerId, Answer = A.Answer_Option_4},
    }
    }
    }
    }).Take(5).ToList();

    return View(model);
    }

    ====>>> my view 

    @model IEnumerable<BoatSafetyExam.ViewModels.Student_Exam_ViewModel>

     
    @{
    ViewBag.Title = "Index";
     

    @using (Html.BeginForm())
    {

    @Html.AntiForgeryToken()

    <div class="form-group">
    @foreach (var item in Model )
    {

    for (int i = 0; i < item.GeneralQuestions.Count; i++)
    {
    var question = item.GeneralQuestions[i];
    <div class="form-group">
    <div class="col-md-12">
    <div class="col-md-8 shadow-sm p-4 mb-4 bg-light font-weight-bold" style="font-family:Arial">
    @Html.HiddenFor(modelItem => question.QuestionId)
    @Html.DisplayFor(modelItem => question.QuestionName, new { htmlAttributes = new { @class = "noWrap form-control", @style = "font-weight:bold;" } })
    </div>

    @foreach (var answer in question.PossibleAnswers)
    {

    <div class="col-md-6" style="font-family:Arial">
    @Html.HiddenFor(modelItem => answer.AnswerId)
    @Html.RadioButtonFor(modelItem => item.GeneralQuestions[i], answer.AnswerId, new { htmlAttributes = new { @required = "required", @type = "radio", @class = "form-control" } })
    @Html.DisplayFor(modelItem => answer.Answer, new { htmlAttributes = new { @class = "noWrapform-control", @style = "font-family:Arial" } })
    <br />
    </div>
    }

    </div>
    </div>
    }

    <hr />
    }

    <div class="form-group col-md-12 ">

    <button id="btnSave"
    type="button" onclick="validateAndSubmit();"
    class=" btn btn-primary">
    FINISHED

    </button>

    </div>
    </div>

    }

    and my view model 

    public class Student_Exam_ViewModel
    {
    public List<Question> GeneralQuestions { get; set; }

    }
    public class Question
    {
    public int QuestionId { get; set; }
    public string QuestionName { get; set; }
    public ICollection<PossibleAnswer> PossibleAnswers { get; set; }
    public int SelectedAnswerId { get; set; }
    }

    public class PossibleAnswer
    {
    public int AnswerId { get; set; }
    public string Answer { get; set; }
    }


    }

    Tuesday, July 7, 2020 8:46 PM

Answers

  • User-474980206 posted

    in html radio button groups are formed by giving them the same name. each one should have a different value. only one radio of the group with the same name can be selected. on post back only the selected radios are sent as name / value pairs.

    to fix the group of answers for one question need the same name: 

    <!-- pass array -->
    @model BoatSafetyExam.ViewModels.Student_Exam_ViewModel[]
    
    <div class="form-group">
        @for (var modelIndex = 0; modelIndex < Model.Length; ++modelIndexdex )
        {
            for (var questionIndex = 0; i < Model[modelIndex].GeneralQuestions.Length; i++)
            {
                var question = Model[modelIndex].GeneralQuestions[i];
                
                <div class="form-group">
                    <div class="col-md-12">
                        <div class="col-md-8 shadow-sm p-4 mb-4 bg-light font-weight-bold" style="font-family:Arial">
                            @Html.HiddenFor(m => m[modelIndex].GeneralQuestions[i].QuestionId)
                            @Html.DisplayFor(m => m[modelIndex].GeneralQuestions[i].QuestionName, 
                                new { 
                                    @class = "noWrap form-control", 
                                    style = "font-weight:bold;" 
                                }
                            )
                        </div>
    
                        @for (var answerIndex = 0; answerIndex < Model[ModelIndex].GeneralQuestions[i].PossibleAnswers.Lengthl ++ answerIndex)
                        {
                            <div class="col-md-6" style="font-family:Arial">
                                @Html.RadioButtonFor(m => m[modelIndex].GeneralQuestions[i].PossibleAnswers, 
                                    Model[modelIndex].GeneralQuestions[i].PossibleAnswers[answerIndex].AnswerId,
                                    new { 
                                        required = "required", 
                                        type = "radio", 
                                        @class = "form-control" ,
                                        id = $"_{ModelIndex}_.GeneralQuestions_{i}_.PossibleAnswers.AnswerId_{answerIndex}"
                                    } 
                                )
                                <label class="noWrapform-control" style="font-family:Arial" for="@($"_{ModelInde}_.GeneralQuestions_{i}_.PossibleAnswers.AnswerId_{answerIndex}")">
                                    @Model[modelIndex].GeneralQuestions[i].PossibleAnswers[answerIndex].Answer
                                </label> 
                                <br />
                            </div>
                            <br />
                        }
                    </div>
                </div>
            }
            <hr />
        }
    </div>
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 8, 2020 12:29 AM
  • User1694748171 posted

    I made some modification on your code and work perfect, thank you so much for your help, your really smart developer.

    @for (var modelIndex = 0; modelIndex < Model.Length; ++modelIndex)
    {
    for (var questionIndex = 0; questionIndex < Model[modelIndex].GeneralQuestions.Count; questionIndex++)
    {
    var question = Model[modelIndex].GeneralQuestions[questionIndex];

    <div class="form-group">
    <div class="col-md-12">
    <div class="col-md-8 shadow-sm p-4 mb-4 bg-light font-weight-bold" style="font-family:Arial">
    @Html.HiddenFor(m => m[modelIndex].GeneralQuestions[questionIndex].QuestionId)
    @Html.DisplayFor(m => m[modelIndex].GeneralQuestions[questionIndex].QuestionName,
    new
    {
    @class = "noWrap form-control",
    style = "font-weight:bold;"
    }
    )
    </div>

    @for (var answerIndex = 0; answerIndex < Model[modelIndex].GeneralQuestions[questionIndex].PossibleAnswers.Count; ++answerIndex)
    {
    <div class="col-md-6" style="font-family:Arial">

    @Html.RadioButtonFor(m => m[modelIndex].GeneralQuestions[questionIndex].PossibleAnswers,
    Model[modelIndex].GeneralQuestions[questionIndex].PossibleAnswers[answerIndex].AnswerId,
    new
    {
    required = "required",
    type = "radio",
    //@class = "form-control",
    //id = $"_{modelIndex}_.GeneralQuestions_{questionIndex}_.PossibleAnswers.AnswerId_{answerIndex}"
    }
    )
    <label class="noWrapform-control" style="font-family:Arial" for="@($"_{modelIndex}_.GeneralQuestions_{questionIndex}_.PossibleAnswers.AnswerId_{answerIndex}")">
    @Model[modelIndex].GeneralQuestions[questionIndex].PossibleAnswers[answerIndex].Answer
    </label>
    <br />
    </div>
    <br />
    }
    </div>
    </div>
    }
    <hr />
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 8, 2020 1:43 PM

All replies

  • User475983607 posted

    Please use the "Insert/Edit code sample when sharing code.

    Radio buttons are grouped (mutually exclusive) by the name attribute.  This is standard HTML syntax.

    https://www.w3schools.com/tags/att_input_type_radio.asp

    The RadioButtonFor<T> you are using in the for...loop creates unique indexed names.  Use the RadioButton helper or basic HTML so you can control the name.  

    https://www.tutorialsteacher.com/mvc/htmlhelper-radiobutton-radiobuttonfor

    https://www.completecsharptutorial.com/asp-net-mvc5/html-radiobutton-and-html-radiobuttonfor-example-in-asp-net-mvc.php

    https://www.aspsnippets.com/Articles/Implement-RadioButton-Group-using-HtmlRadioButton-in-ASPNet-MVC.aspx

    Tuesday, July 7, 2020 9:59 PM
  • User-474980206 posted

    in html radio button groups are formed by giving them the same name. each one should have a different value. only one radio of the group with the same name can be selected. on post back only the selected radios are sent as name / value pairs.

    to fix the group of answers for one question need the same name: 

    <!-- pass array -->
    @model BoatSafetyExam.ViewModels.Student_Exam_ViewModel[]
    
    <div class="form-group">
        @for (var modelIndex = 0; modelIndex < Model.Length; ++modelIndexdex )
        {
            for (var questionIndex = 0; i < Model[modelIndex].GeneralQuestions.Length; i++)
            {
                var question = Model[modelIndex].GeneralQuestions[i];
                
                <div class="form-group">
                    <div class="col-md-12">
                        <div class="col-md-8 shadow-sm p-4 mb-4 bg-light font-weight-bold" style="font-family:Arial">
                            @Html.HiddenFor(m => m[modelIndex].GeneralQuestions[i].QuestionId)
                            @Html.DisplayFor(m => m[modelIndex].GeneralQuestions[i].QuestionName, 
                                new { 
                                    @class = "noWrap form-control", 
                                    style = "font-weight:bold;" 
                                }
                            )
                        </div>
    
                        @for (var answerIndex = 0; answerIndex < Model[ModelIndex].GeneralQuestions[i].PossibleAnswers.Lengthl ++ answerIndex)
                        {
                            <div class="col-md-6" style="font-family:Arial">
                                @Html.RadioButtonFor(m => m[modelIndex].GeneralQuestions[i].PossibleAnswers, 
                                    Model[modelIndex].GeneralQuestions[i].PossibleAnswers[answerIndex].AnswerId,
                                    new { 
                                        required = "required", 
                                        type = "radio", 
                                        @class = "form-control" ,
                                        id = $"_{ModelIndex}_.GeneralQuestions_{i}_.PossibleAnswers.AnswerId_{answerIndex}"
                                    } 
                                )
                                <label class="noWrapform-control" style="font-family:Arial" for="@($"_{ModelInde}_.GeneralQuestions_{i}_.PossibleAnswers.AnswerId_{answerIndex}")">
                                    @Model[modelIndex].GeneralQuestions[i].PossibleAnswers[answerIndex].Answer
                                </label> 
                                <br />
                            </div>
                            <br />
                        }
                    </div>
                </div>
            }
            <hr />
        }
    </div>
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 8, 2020 12:29 AM
  • User634495354 posted

    Hi luay20032003,

    Can you provider more codes? When I try to reproduce your problem, there're many error  especially in controller and model. 

    I need code about your db.Exam_questions and db.Exam_Answers, and how do you make those model correspond to the database table.

    Best regards,

    Bruce12138

    Wednesday, July 8, 2020 3:21 AM
  • User1694748171 posted

    what is the value of (i) in 

        for (var questionIndex = 0; i < Model[modelIndex].GeneralQuestions.Length; i++)
    Wednesday, July 8, 2020 1:05 PM
  • User1694748171 posted

    I made some modification on your code and work perfect, thank you so much for your help, your really smart developer.

    @for (var modelIndex = 0; modelIndex < Model.Length; ++modelIndex)
    {
    for (var questionIndex = 0; questionIndex < Model[modelIndex].GeneralQuestions.Count; questionIndex++)
    {
    var question = Model[modelIndex].GeneralQuestions[questionIndex];

    <div class="form-group">
    <div class="col-md-12">
    <div class="col-md-8 shadow-sm p-4 mb-4 bg-light font-weight-bold" style="font-family:Arial">
    @Html.HiddenFor(m => m[modelIndex].GeneralQuestions[questionIndex].QuestionId)
    @Html.DisplayFor(m => m[modelIndex].GeneralQuestions[questionIndex].QuestionName,
    new
    {
    @class = "noWrap form-control",
    style = "font-weight:bold;"
    }
    )
    </div>

    @for (var answerIndex = 0; answerIndex < Model[modelIndex].GeneralQuestions[questionIndex].PossibleAnswers.Count; ++answerIndex)
    {
    <div class="col-md-6" style="font-family:Arial">

    @Html.RadioButtonFor(m => m[modelIndex].GeneralQuestions[questionIndex].PossibleAnswers,
    Model[modelIndex].GeneralQuestions[questionIndex].PossibleAnswers[answerIndex].AnswerId,
    new
    {
    required = "required",
    type = "radio",
    //@class = "form-control",
    //id = $"_{modelIndex}_.GeneralQuestions_{questionIndex}_.PossibleAnswers.AnswerId_{answerIndex}"
    }
    )
    <label class="noWrapform-control" style="font-family:Arial" for="@($"_{modelIndex}_.GeneralQuestions_{questionIndex}_.PossibleAnswers.AnswerId_{answerIndex}")">
    @Model[modelIndex].GeneralQuestions[questionIndex].PossibleAnswers[answerIndex].Answer
    </label>
    <br />
    </div>
    <br />
    }
    </div>
    </div>
    }
    <hr />
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 8, 2020 1:43 PM
  • User1694748171 posted

    Thank you for your help

    Wednesday, July 8, 2020 1:44 PM
  • User1694748171 posted

    My answer is below the page. but thank you for your help.

    Wednesday, July 8, 2020 1:45 PM
  • User1694748171 posted

    Hi I know you already answers my question and I want to make some modification on the code. in the code above generalQuestion had the list of questions I want to show it. si instead of that I need to used viewbage to pass a list to the view 

    this is for controlle

    public ActionResult Index(string StudentName)
    {
    ViewBag.Name = StudentName;
    Student_Exam_ViewModel vm = new Student_Exam_ViewModel();
    var model = (from q in db.Exam_Questions
    join A in db.Exam_Answers on q.QuestionId equals A.QuestionId
    select new Student_Exam_ViewModel
    {
    GeneralQuestions = new List<Questions>
    {
    new Questions
    {

    QuestionName = q.QuestionName ,
    Categories_QuestionName = new Pick_Questions().Get_Categories_Questions(),
    AssessmentId = q.AssessmentId,
    Assessment_Section = q.Assessment_Section,


    PossibleAnswers = new List<PossibleAnswer>
    {
    new PossibleAnswer { AnswerId = A.AnswerId, Answer = A.Answer_Option_1},
    new PossibleAnswer { AnswerId = A.AnswerId, Answer = A.Answer_Option_2},
    new PossibleAnswer { AnswerId = A.AnswerId, Answer = A.Answer_Option_3},
    new PossibleAnswer { AnswerId = A.AnswerId, Answer = A.Answer_Option_4},
    }


    }

    }
    }).ToList();


    ViewBag.PickQuestions = new Pick_Questions().Get_Categories_Questions();  >>>>> used this instead of generalQuestion 

    return View(model.ToArray());
    }

    --- and the function for   Pick_Questions().Get_Categories_Questions();  is below

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using BoatSafetyExam.Models;
    using BoatSafetyExam.ViewModels;
    namespace BoatSafetyExam.Global
    {
    public class Pick_Questions
    {
    private BoatExamSafetyContext db = new BoatExamSafetyContext();
    public List<string> Get_Categories_Questions()
    {

    List<string> questions = new List<string>();
    List<string> pickList = new List<string>();
    var GenreList = new List<string>();

    var assquery = from e in db.Exam_Questions orderby e.Assessment_Section select e.Assessment_Section;
    GenreList.AddRange(assquery.Distinct());
    // var data = db.Exam_Questions.SqlQuery("Select * from BE.Exam_Questions").ToList();

    foreach (var item in GenreList)
    {
    // Pick questions from category 1 : The Boat
    if (item == "1.1")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    //var s = db.Exam_Questions.SqlQuery("Select top 2 * from BE.Exam_Questions where assessment_section='1.1' order by newid()").ToList();
    pickList.AddRange(pick_Question);
    }
    // Pick questions from category 2 : The Boating Equipment
    if (item == "2.1")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "2.2")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "2.3")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(2).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "2.4")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "2.5")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "2.8")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "2.10")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }

    // pick question from section 3: Trip Planning and Preparation
    if (item == "3.1")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "3.2")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "3.3")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "3.4")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "3.5")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "3.6")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "3.7")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }

    // pick question from section 4: Safe Boat Operation
    if (item == "4.1")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(4).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "4.2")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(3).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "4.3.1")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "4.3.2")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(2).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "4.3.3")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(2).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "4.3.4")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(2).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "4.3.5")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "4.4")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(2).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "4.5")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "4.6")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "4.7")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "4.8")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    // pick question from section 5: Emergency Preparedness
    if (item == "5.1")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "5.2")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(3).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "5.3")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "5.4")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "5.5")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }

    // pick question from section 6: Other Water Activities

    if (item == "6.1")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(3).ToList();
    pickList.AddRange(pick_Question); ;
    }
    if (item == "6.2")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "6.4")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }
    if (item == "6.5")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(1).ToList();
    pickList.AddRange(pick_Question);
    }

    // pick question from section 8: State Specific Information
    if (item == "8")
    {
    var pick_Question = db.Exam_Questions.OrderBy(t => Guid.NewGuid()).Where(x => x.Assessment_Section == item).Select(x => x.QuestionName).Take(10).ToList();
    pickList.AddRange(pick_Question);
    }

    }

    return pickList;


    }
    }
    }

    Monday, July 13, 2020 8:52 PM