asp.net mvc 4 - @Viewbag not displaying anything -


i'm making simple quiz in asp.net mvc4. first application i'm new this.

the problem is, when display @viewbag.ans1 (or ans2 etc.), nothing displays. i've done lot of searching, think may have more 1 problem.

per asawyer's question, reason didn't use model figured didn't need database keep track of user's answers , viewbag suffice (not sure if figured right though). using else though (the quiz answers).

here results view. @viewbag.ans1 displays nothing on output.:

@{     viewbag.title = "results"; }  <h2>results</h2>  <p># correct: 9/10</p> <!--hardcoded, change later-->  <p>grade: </p> <!--hardcoded, change later--> <p>your answers: </p> <p>1. @viewbag.ans1</p> <p>2. @viewbag.ans2 </p> <p>3. @html.raw(viewbag.ans3)</p> <!--trying different way here--> <p>4. @html.raw(viewbag.ans4)</p> <!--here too--> <p>5. @html.raw(viewbag.ans5)</p> <!--here too--> <p>6. @viewbag.ans6</p> <p>7. @viewbag.ans7</p> <p>8. @viewbag.ans8</p> <p>9. @viewbag.ans9</p> <p>10. @viewbag.ans10</p>   <div>     @html.actionlink("retry test?", "index") </div> 

here question_1 view. i'm showing because i'm setting answer variable in @html.actionlink below:

@{     viewbag.title = "question_1"; }  @using (html.beginform())  {     @html.validationsummary(true) } <ol class="round">     <li class="one">         name of website?     </li> </ol>         @html.actionlink("yes", "question_2", new{ answer = true} )         @html.actionlink("no", "question_2",  new{ answer = false} ) 

here quiz_controller:

using system; using system.collections.generic; using system.web; using system.web.mvc;  namespace matts_quiz.controllers {     public class quizcontroller : controller     {         //          // get: /index/           public actionresult index()         {             return view();         }          //          // get: /question_1/           public actionresult question_1()         {             return view();         }          //          // get: /question_2/           public actionresult question_2(bool answer)         {             if (answer == true)             {                 viewbag.ans1 = "y";             }             else if (answer == false)             {                 viewbag.ans1 = "n";             }             else             {                 viewbag.ans1 = "miss";             }             return view();         } (...etc...) 


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -