Help
Sample Code

This is a simple adaptive assessment engine written in ASP.NET MVC. It displays the questions in the order received and enables the correct buttons.

public class AdaptiveAssessmentController : Controller
{
    // Turn of validation of the post data
    [ValidateInput(false)]
    public string Sequential()
    {
        // Load the parameters we need, ignore the rest
        string action = Request.Params["action"];
        string state = Request.Params["state"];
        XElement questionList = XElement.Parse(Request.Params["questionlist"]);
        XElement submission = XElement.Parse(Request.Params["submission"]);

        int questionCount = questionList.Elements().Count();
        int submissionCount = submission.Elements().Count();

        XElement response = new XElement("response");

        // State stores our current question, assume 0 if there is no state
        int question = string.IsNullOrEmpty(state) ? 0 : int.Parse(state);

        switch (action)
        {
            case "start": 
                // Nothing to do
                break;
            case "next":
                // Go to the next question
                question++;
                break;
            case "previous":
                // Go the the previous question
                question--;
                break;
            case "submit":
                // Submit the exam
                question = questionCount;
                break;
            default:
                response.SetAttributeValue("display", "html");
                response.Add(new XElement("html", "Bad action: " + action));
                break;
        }
            
        // We presented all the questions, submit now
        if (question >= questionCount)
        {
            response.SetAttributeValue("display", "done");
        }
        else
        {
            // Either use a new question from questionlist or an existing one from submission
            if (question >= submissionCount)
            {
                // Add new question
                response.SetAttributeValue("display", "question");
                response.SetAttributeValue("partid", questionList.Elements().ElementAt(question).Attribute("partid").Value);
            }
            else
            {
                // Use existing question
                response.SetAttributeValue("display", "submission");
                response.SetAttributeValue("partid", submission.Elements().ElementAt(question).Attribute("partid").Value);
            }

            // Add Buttons
            XElement buttons = new XElement("buttons");

            if (question > 0)
            {
                // Not on the first question? Add a previous button
                buttons.Add(new XElement("button", new XAttribute("action", "previous")));
            }

            if (question < questionCount - 1)
            {
                // Not on the last question? Add a next button
                buttons.Add(new XElement("button", new XAttribute("action", "next")));
            }
            else
            {
                // On the last question? Add a submit button
                buttons.Add(new XElement("button", new XAttribute("action", "submit")));
            }
            // Save the question number as the state
            response.Add(buttons, new XElement("state",question.ToString()));
        }

        Response.ContentType = "text/xml";
        Response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
        return response.ToString();
    }
}
See Also
Adaptive Assessment API Request Parameters Response Data Sample Scenario