Domanda

Lavorando su un test online.

Ho 3 tavoli

  1. Domande
  2. Soggetto
  3. Discussione

Ho creato una procedura memorizzata che restituisce 25 record casuali. Voglio salvarlo in memoria e quindi visualizzare 1 domanda alla volta con AJAX. Non voglio colpire il database 25 volte perché ci sono molti utenti, ho provato a archiviare il risultato in viewstate ma non sono in grado di eseguirne il cast. se uso

Dim qus = from viewstate("questions") 

funziona, ma non funziona quando recupero 1 record alla volta.

Codice:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
        ViewState.Add("QuestionNo", 0)
        Dim qus = From q In PML.PM_SelectRandomQuestionFM Select q
        viewstate.add("questions",qus)
        LoadQuestion(0)
    End If
End Sub



Private Sub LoadQuestion(ByVal i As Integer)
    Dim QuestionNo As Integer = CType(ViewState("QuestionNo"), Integer) + 1

    Try
        If QuestionNo <= 25 Then

            Dim qus = viewstate("questions")

            Me._subjectTopic.Text = String.Format("<b>Subject:</b> {0} -- <b>Topic:</b> {1}", qus(i).subjectName, qus(i).TopicName)
            Me._question.Text = " " & qus(i).Question
            Me._answer1.Text = " " & qus(i).Answer1
            Me._answer2.Text = " " & qus(i).Answer2
            Me._answer3.Text = " " & qus(i).Answer3
            Me._answer4.Text = " " & qus(i).Answer4
            Me._questionNo.Text = String.Format("Question No. {0} / 25", QuestionNo)
            ViewState.Add("QuestionNo", QuestionNo)
        Else
            Server.Transfer("freeMemberResult.aspx")
        End If

    Catch ex As Exception
        Throw New System.Exception(ex.ToString)
    End Try
End Sub

Ho provato a lanciare l'oggetto su

Dim qus = CType(ViewState("questions"), IQueryable(Of PM_SelectRandomQuestionFMResult)) 

ma poi ottengo questo errore

  

System.Linq.Enumerable + WhereSelectEnumerableIterator`2

AIUTO o se esiste un altro metodo per farlo, se il mio metodo di fare test online è sbagliato.

Saluti

È stato utile?

Soluzione

IMO, stai progettando troppo questo. Perché cercare di conservare i dati in memoria? Perché non scrivere ogni domanda su un div e quindi nascondere tutti i div di domanda tranne la "domanda corrente".

Molto più facile da implementare e non stai colpendo il server con diverse chiamate AJAX, Questo rende anche molto più semplice il salvataggio dello stato (domande con risposta in precedenza, ecc.).

Altri suggerimenti

Hai provato a usare Session solo per mantenere lo stato? C'è un requisito che ti proibisce di farlo?

Dim qus = CType(Me.Session("questions"), IQueryable(Of PM_SelectRandomQuestionFMResult))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top