title: Set Dropdownlist Selected Value in the View
body: <p>I need to set the setectedValue of a DropDownList using razor, but because it's a list used several times in the same page, I can't set the selected value in the Controller, so how can I set it in the View?</p>
  
  <p>Actual Controller List code:</p>
  
  <pre><code>ViewBag.CargaTipos = new SelectList(db.CargaTipos, "Id", "Nome").OrderBy(c =&gt; c.Text);
  </code></pre>
  
  <p>Actual View:</p>
  
  <pre><code>@Html.DropDownListFor(modelItem =&gt; item.CargaTipo.Id, (IEnumerable&lt;SelectListItem&gt;)ViewBag.CargaTipos)
  </code></pre>
  
  <p>Models:</p>
  
  <pre><code>[Table("Cargas")]
  public class Carga
  {
      [Key]
      [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }
  
      [Required]
      [ForeignKey("CargaTipo")]
      public int CargaTipo_Id { get; set; }
  
      [Display(Name = "Tipo de Carga")]
      public virtual CargaTipo CargaTipo { get; set; }
  }
  
  [Table("CargaTipos")]
  public partial class CargaTipo
  {
      public CargaTipo()
      {
          this.Cargas = new HashSet&lt;Carga&gt;();
      }
  
      [Key]
      [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }
      public string Nome { get; set; }
  
      public virtual ICollection&lt;Carga&gt; Cargas { get; set; }
  }
  </code></pre>