title: MVC 3 - Getting on server side the value from a dropdown changed on javascript
body: <p>I have a javascript that change the value from my dropdown, and when I save the form, the value can't be captured on server side.</p>
  
  <p>Follow bellow some of the code:</p>
  
  <pre><code>  &lt;div class="editor-field"&gt;
      @Html.DropDownListFor(model =&gt; model.CategoriaId,
          Model.Categorias
              .Where(c =&gt; c.Id != Model.ContentId)
              .Select(c =&gt; new SelectListItem {
                  Selected = c.Id == Model.CategoriaId,
                  Text = c.Type + " - " +c.Name,
                  Value = c.Id.ToString()
              } ),
              "Selecione uma Categoria")
  
           @Html.Hidden("hdnValue", Model.hndCategoriaId) // my hidden value
    &lt;/div&gt;
  </code></pre>
  
  <p>Javascript that change the dropdown and the hidden value</p>
  
  <pre><code>function change(item) {
  
  var valueArtigo;
  var ddl = document.getElementById('Categoria_CategoriaId');         
  for (i = 0; i &lt; ddl.options.length; i++) {
     if (ddl.options[i].text.toUpperCase().indexOf("ARTIGOS") != -1)
     valueArtigo = ddl.options[i].value;
  }
  document.getElementById("Categoria_CategoriaId").value = valueArtigo;
  document.getElementById("Categoria_hdnValue").value = valueArtigo;
  }
  </code></pre>
  
  <p>Getting back on server side, I am trying to save the value on database.</p>
  
  <pre><code>public void UpdateCategoriaForContentItem(ContentItem item, EditCategoriaViewModel model)
  {
      if ((model.CategoriaId != null)||(model.hndCategoriaId != null)) // both are null
      {...}
  }
  </code></pre>
  
  <p>Thanks,</p>