Rodrigo Fernando Luna
Rodrigo Fernando Luna

Reputation: 21

How to get the values of radio buttons' values that where assigned with a variable to store in a data base using Razor

guys! First of all thanks in advance for the time you take to help me. I have this code:

@{
    int Contador = 1 ;
    var db = Database.Open("StarterSite");
    var Clases = db.Query("SELECT TOP 5 PreguntaId, Pregunta, Respuest1, 
    Respuest2, Respuest3, Respuest4, RespuestaCorrecta FROM ReactivosExamen 
    ORDER BY NEWID()");  
    string[] PreguntaId = new string[7];
    string[] RespuestaEscogida = new string[120];

}
<!DOCTYPE html>

<html lang="en">
    <head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <form method="post" action="~/ExamenColocacion/ExamenDeColocacion2">
        @foreach(var Reactivo in Clases)
        { 
        <fieldset>
            <legend></legend>
                <label>@Contador . @Reactivo.Pregunta.ToString()</label>
                <label>
                    <input type="radio" name="@Contador" value="1"> 
        @Reactivo.Respuest1.ToString()
                </label>
                <label>
                    <input type="radio" name="@Contador" value="2"> 
        @Reactivo.Respuest2.ToString()
                </label>
                <label>
                    <input type="radio" name="@Contador" value="3"> 
       @Reactivo.Respuest3.ToString()
                </label>
                <label>
                    <input type="radio" name="@Contador" value="4"> 
       @Reactivo.Respuest4.ToString()
                </label><br/><br/>
        </fieldset>
        Contador++;
        PreguntaId [Contador] = Reactivo.PreguntaId.ToString();            
        <h3>@PreguntaId[Contador]</h3>                     
        }
        <input type="submit" value="Finalizar Examen" /> 
    </form>
</body>
</html>

The code takes 5 random questions from a Table and it also takes their respective 4 answers to store them in radio buttons. What i want to do is to store the selected radio button answers of the questions into a table. Could you help me please?

Upvotes: 1

Views: 40

Answers (1)

Rodrigo Fernando Luna
Rodrigo Fernando Luna

Reputation: 21

I answered my own question. It is actually very simple. You just need to declare the array and the use it into the sql by using a for loop or any loop. for instance:

int[] Contador6 = new int[60]
for(Contador6 = 0; Contador6 <= 60; Contador6++)
            {
                db.Execute(InsertarInfo[Contador6],Preguntas[Contador6],Respuestas[Contador6], RespuestaCorrecta[Contador6],Clave);
            }

Upvotes: 1

Related Questions