title: Passing values from the view to the controller in MVC4
body: <p>I'm trying to pass these textbox values to the controller:</p>
  
  <pre><code>@model DTOs.QuestionDTO
  
  @{
      ViewBag.Title = "AddQuestion";
  }
  
  &lt;h2&gt;AddQuestion&lt;/h2&gt;
  
  @using (Html.BeginForm("AddQuestionDB", "Exam"))
  {
      &lt;fieldset&gt;
          &lt;legend&gt;Add Question&lt;/legend&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.QuestionDes)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.QuestionDes , new { @id="question" , @name="question"})
              @Html.ValidationMessageFor(model =&gt; model.QuestionDes)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Answer1)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.Answer1 , new { @id="a1" , @name="a1"})
              @Html.ValidationMessageFor(model =&gt; model.Answer1)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Answer2)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.Answer2 , new { @id="a2" , @name="a2"})
              @Html.ValidationMessageFor(model =&gt; model.Answer2)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Answer3)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.Answer3 , new { @id="a3" , @name="a3"})
              @Html.ValidationMessageFor(model =&gt; model.Answer3)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Answer4)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.Answer4 , new { @id="a4" , @name="a4"})
              @Html.ValidationMessageFor(model =&gt; model.Answer4)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Correct)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.Correct , new { @id="correct" , @name="correct"})
              @Html.ValidationMessageFor(model =&gt; model.Correct)
          &lt;/div&gt;
  
          &lt;p&gt;
              &lt;input type="submit" value="Add" /&gt;
          &lt;/p&gt;
      &lt;/fieldset&gt;
  }
  
  &lt;div&gt;
      @Html.ActionLink("Back to Login", "Login")
  &lt;/div&gt;
  
  @section Scripts {
      @Scripts.Render("~/bundles/jqueryval")
  }
  </code></pre>
  
  <p>this is how my controller method looks like:</p>
  
  <pre><code>public ActionResult AddQuestionDB(string question, string a1, string a2, string a3, string a4, string correct)
          {
              ViewBag.a1 = a1;
              ViewBag.a2 = a2;
              ViewBag.a3 = a3;
              ViewBag.a4 = a4;
              ViewBag.correct = correct;
              return View();
          }
  </code></pre>
  
  <p>And i have created a View to display this Viewbag variables... but these variables wont come up.
  it seem to be that these variables are null..</p>
  
  <pre><code>@{
      ViewBag.Title = "AddQuestionDB";
  }
  
  &lt;h2&gt;AddQuestionDB&lt;/h2&gt;
  
  &lt;p&gt;@Session["q"]&lt;/p&gt;
  &lt;p&gt;@ViewBag.question&lt;/p&gt;
  &lt;p&gt;@ViewBag.a1&lt;/p&gt;
  &lt;p&gt;@ViewBag.a2&lt;/p&gt;
  &lt;p&gt;@ViewBag.a3&lt;/p&gt;
  &lt;p&gt;@ViewBag.a4&lt;/p&gt;
  &lt;p&gt;@ViewBag.correct&lt;/p&gt;
  </code></pre>
  
  <p>this is how my DTO looks like:</p>
  
  <pre><code>namespace DTOs
  {
      public class QuestionDTO
      {
          public int ID { get; set; }
          public string QuestionDes { get; set; }
          public string Answer1 { get; set; }
          public string Answer2 { get; set; }
          public string Answer3 { get; set; }
          public string Answer4 { get; set; }
          public int Correct { get; set; }
  
      }
  }
  </code></pre>
  
  <p>Can you please explain, how i should do this??
  thank you!!!</p>