title: Passing values in a view from controller after getting those values from same view
body: <p>I am new to MVC. I want to get "fromDate" and "ToDate" from a view. In the same view, I need three DropDownLists that are empty and hidden.</p>
  
  <p>After clicking on the submit button, those DropDownLists should be visible and filled with data based on the dates picked.</p>
  
  <p>But I am getting 'null reference' error on view page.</p>
  
  <p><strong>My View Page is</strong></p>
  
  <pre><code>&lt;h2&gt;View Data in Database&lt;/h2&gt;
  &lt;table&gt;&lt;tr&gt;&lt;td&gt;
  @using(Html.BeginForm("ViewPage1","Home"))
  {
     &lt;table&gt;&lt;tr&gt;&lt;td&gt;From Date:&lt;/td&gt;
                &lt;td&gt;@html.TextBoxFor(m=&gt;m.FromDate,"{0:dd/MM/yyyy}")&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;&lt;td&gt;To Date:&lt;/td&gt;
                &lt;td&gt;@html.TextBoxFor(m=&gt;m.ToDate,"{0:dd/MM/yyyy}")&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;&lt;td&gt;&lt;input type="submit" Value="Show"&gt;&lt;/td&gt;
                &lt;td&gt;&lt;input type="submit" Value="Show"&gt;&lt;/td&gt;
            &lt;/tr&gt;
     &lt;/table&gt;
     &lt;div id="ShowDropBoxes"&gt;
     &lt;table&gt;
          &lt;tr&gt;&lt;td&gt;@Html.CheckBox("Production Order:", new{id="ck1"})&lt;/td&gt;
              &lt;td&gt;@Html.DropDownlistFor(m=&gt;m.ProdNo, Model.ProdOrdList, "Select Production Order")&lt;/td&gt;
          &lt;/tr&gt;
           &lt;tr&gt;&lt;td&gt;@Html.CheckBox("Part Number:", new{id="ck2"})&lt;/td&gt;
              &lt;td&gt;@Html.DropDownlistFor(m=&gt;m.PartNo, Model.PartNoList, "Select Part Number")&lt;/td&gt;
          &lt;/tr&gt;
           &lt;tr&gt;&lt;td&gt;@Html.CheckBox("Status:", new{id="ck3"})&lt;/td&gt;
              &lt;td&gt;@Html.DropDownlistFor(m=&gt;m.StatusTxt, Model.StatusList, "Select Status")&lt;/td&gt;
          &lt;/tr&gt;
     &lt;/table&gt;
     &lt;/div&gt;
  </code></pre>
  
  <p><strong>My Model is</strong></p>
  
  <pre><code>  public class HomeModel
    {
        public DateTime FromDate {get; set; }
        public DateTime ToDate {get; set; }
        public string ProdNo {get; set; }
        public string PartNo {get; set; }
        public int status {get; set; }
        public System.Web.Mvc.SelectList ProdNoList {get; set; }
        public System.Web.Mvc.SelectList PartNoList {get; set; }
        public System.Web.Mvc.SelectList StatusList {get; set; }
    }
  </code></pre>
  
  <p><strong>Controller Is:-</strong></p>
  
  <pre><code>  public class HomeController: Controller
    {
         Repository List_in_Repository = new Repository();
  
         public ActionResult ViewPage1()
         {
             return View();
         }
         [HttpPost]
         public ActionResult ViewPage(HomeModel model)
         {
               string fromdate = model.FromDate.Tostring("yyyyMMdd");
               string todate = model.ToDate.Tostring("yyyyMMdd");
               model.ProdNoList = new SelectList(List_in_Repository.GetProductionOrders(fromdate,todate));
               model.PartNoList= new SelectList(List_in_Repository.GetPartNumbers(fromdate,todate));
               model.StatusList = new SelectList(List_in_Repository.GetStatus(fromdate,todate));
              return View(model);
         }
     }
  </code></pre>