Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Implementation advice for quiz with 4 choice questions

Implementation advice for quiz with 4 choice questions

Scheduled Pinned Locked Moved ASP.NET
asp-netquestioncsharphtmlarchitecture
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Farhad Eft
    wrote on last edited by
    #1

    Hey, I', looking for some implementation advice. I am creating this ASP.NET MVC page for quizzes that each course may have a different number of questions with 4 choices. I would like to send the questions to my view as my Model, and by submitting the form, my controller endpoint receives the Id of the questions and selected answers. Can you please give me some tips that how to send such information to my controller using the sample code I wrote in the following? Thank you in advance. My Model

    public class QuizQuestion
    {
    [Key]
    public int QuestionId { get; set; }
    public int CourseId { get; set; }
    public int Order { get; set; }
    public string Question { get; set; }
    public string Choice1 { get; set; }
    public string Choice2 { get; set; }
    public string Choice3 { get; set; }
    public string Choice4 { get; set; }
    public int RightAnswer { get; set; }
    }

    My View

    using (Html.BeginForm("Submit", "Quiz", FormMethod.Post, new { }))
    {
    @Html.AntiForgeryToken()
    foreach (var item in Model.QuizJustQuestionsDto)
    {

                            @(item.Order + ". " + item.Question)  
                            @Html.RadioButton(item.QuestionId.ToString(), 1) @Html.Label(item.Choice1)  
                            @Html.RadioButton(item.QuestionId.ToString(), 2) @Html.Label(item.Choice2)  
                            @Html.RadioButton(item.QuestionId.ToString(), 3) @Html.Label(item.Choice3)  
                            @Html.RadioButton(item.QuestionId.ToString(), 4) @Html.Label(item.Choice4)
                        
    
                        }
    
    F 1 Reply Last reply
    0
    • F Farhad Eft

      Hey, I', looking for some implementation advice. I am creating this ASP.NET MVC page for quizzes that each course may have a different number of questions with 4 choices. I would like to send the questions to my view as my Model, and by submitting the form, my controller endpoint receives the Id of the questions and selected answers. Can you please give me some tips that how to send such information to my controller using the sample code I wrote in the following? Thank you in advance. My Model

      public class QuizQuestion
      {
      [Key]
      public int QuestionId { get; set; }
      public int CourseId { get; set; }
      public int Order { get; set; }
      public string Question { get; set; }
      public string Choice1 { get; set; }
      public string Choice2 { get; set; }
      public string Choice3 { get; set; }
      public string Choice4 { get; set; }
      public int RightAnswer { get; set; }
      }

      My View

      using (Html.BeginForm("Submit", "Quiz", FormMethod.Post, new { }))
      {
      @Html.AntiForgeryToken()
      foreach (var item in Model.QuizJustQuestionsDto)
      {

                              @(item.Order + ". " + item.Question)  
                              @Html.RadioButton(item.QuestionId.ToString(), 1) @Html.Label(item.Choice1)  
                              @Html.RadioButton(item.QuestionId.ToString(), 2) @Html.Label(item.Choice2)  
                              @Html.RadioButton(item.QuestionId.ToString(), 3) @Html.Label(item.Choice3)  
                              @Html.RadioButton(item.QuestionId.ToString(), 4) @Html.Label(item.Choice4)
                          
      
                          }
      
      F Offline
      F Offline
      Farhad Eft
      wrote on last edited by
      #2

      I found this awesome post about solving my issue: asp.net mvc 3 - Getting a list of radio button values in ASP MVC 3 - Stack Overflow[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups