I have edited de Create view to add a hidden field control, but i cant get the value
<div class="form-group">
@Html.LabelFor(model => model.EmpresaId, "Empresa", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("EmpresaId", null, htmlAttributes: new { @class = "form-control", @disabled = "disabled" })
@Html.HiddenFor(model => model.EmpresaId)
@Html.ValidationMessageFor(model => model.EmpresaId, "", new { @class = "text-danger" })
</div>
</div>
html created is:
<div class="form-group">
<label class="control-label col-md-2" for="EmpresaId">Empresa</label>
<div class="col-md-10">
<select class="form-control" disabled="disabled" id="EmpresaId" name="EmpresaId">
<option selected="selected" value="1">Farmacia MZ</option>
<option value="2">Credesa</option>
</select>
<input length="19" id="EmpresaId" name="EmpresaId" type="hidden" value="">
<span class="field-validation-valid text-danger" data-valmsg-for="EmpresaId" data-valmsg-replace="true"></span>
</div>
</div>
As you can see hidden input has no value.
On Controller is DropDownList default value set:
public ActionResult Create()
{
ApplicationUser usr = db.Users.Find(User.Identity.GetUserId().ToString());
int userId = (int)usr.EmpresaId;
ViewBag.CategoriaId = new SelectList(db.Categorias, "CategoriaId", "Nombre");
ViewBag.EmpresaId = new SelectList(db.Empresas, "EmpresaId", "Nombre", userId); <-- defalut value for disabled DropDownList
ViewBag.MarcaId = new SelectList(db.Marcas, "MarcaId", "Nombre");
return View();
}
I've searched quite a lot but i dont understand what is the mistake. Help is wellcome !