title: Set @Html.Dropdownlistfor to session in MVC 4
body: <p>After lot of tries and research , finally ended up with this.</p>
  
  <p>I have couple of view(namely Index and Create) in my MVC 4 application and both having a dropdown with similar functionality.
  I can select a value from the Dropdown in Index and move forward to create.Also I can select the value from my Dropdown in Create view as well.</p>
  
  <p>If I select any value from the index view then that value is set to a session.My problem is that if I select any value from Index view that value should be carried to the create view for which I tried with session concept.</p>
  
  <p>In both of my action methods(<strong>Index</strong> and <strong>Create(Get)</strong>) I am able to bind the list of values to the dropdown which works fine.</p>
  
  <p><strong>Index</strong> view:</p>
  
  <pre><code>@Html.LabelFor(model =&gt; model.document.TeamId, "Team") &amp;nbsp;
  @Html.DropDownListFor(model =&gt; model.document.TeamId, new SelectList(Model.ddlTeam, "Value", "Text"), "Select Team", new { id = "TeamID", onchange = "GetProjects()", @class = "form-control", UpdateTargetId = "atag" })
  @Html.ValidationMessageFor(model =&gt; model.document.TeamId)
  </code></pre>
  
  <p>Now the selected value is set to a session which is working fine.(Session["TeamId"] = somevalue;)</p>
  
  <p>Then in my create view , I am checking it as(which I found from somebody's post in order to assign the session value to the dropdownlistfor ) as:</p>
  
  <p><strong>Create View:</strong></p>
  
  <pre><code>@Html.LabelFor(model =&gt; model.document.TeamId, "Team", new { @class = "control-label col-sm-3" }) 
  @if (Session["TeamId"] == null)
  { 
     @Html.DropDownListFor(model =&gt; model.document.TeamId, new SelectList(Model.ddlTeam, "Value", "Text"), "Select Team", new { id = "TeamID", onchange = "GetProjects()", @class = "form-control", UpdateTargetId = "atag" })
  }
  else
  { 
    @Html.DropDownListFor(model =&gt; model.document.TeamId, new SelectList(Model.ddlTeam, "Value", "Text", Session["TeamId"]), "Select Team", new { id = "TeamID", onchange = "GetProjects()", @class = "form-control", UpdateTargetId = "atag" })
   }
   @Html.ValidationMessageFor(model =&gt; model.document.TeamId)
  </code></pre>
  
  <p>But again even after selecting the value from index view the value is not getting carried to the create view.</p>
  
  <p>Please suggest where am I doing wrong or how should I make it work?
  Thanks in advance.</p>