I'm doing a form in the VIEW, but the fields where I use radio and select (option) are not passing their values to the Controller. If anyone knows why.
My VIEW:
@model GerenciadorDeAtividades.Dominio.RecursoDominio
@{
ViewBag.Title = "Cadastrar";
}
<div class="container">
<div class="jumbotron">
<h2>Cadastrar</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Novo Recurso</legend>
<div class="row">
<div class="col-md-9">
<div class="form-group">
@Html.LabelFor(model => model.Nome)
@Html.TextBoxFor(model => model.Nome, new { @class = "form-control", style = "width: 50%" })
@Html.ValidationMessageFor(model => model.Nome)
</div>
<div class="form-group">
@Html.LabelFor(model => model.Categoria)
<select class="form-control" style = "width: 40%">
<option value="Gerente">Gerente</option>
<option value="Coordenador">Coordenador</option>
<option value="Desenvolvedor">Desenvolvedor</option>
<option value="Funcional">Funcional</option>
</select>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UsuarioSAP)
@Html.TextBoxFor(model => model.UsuarioSAP, new { @class = "form-control", style = "width: 40%"})
@Html.ValidationMessageFor(model => model.UsuarioSAP)
</div>
<div class="form-group">
@Html.LabelFor(model => model.UsuarioAD)
@Html.TextBoxFor(model => model.UsuarioAD, new { @class = "form-control", style = "width: 40%" })
@Html.ValidationMessageFor(model => model.UsuarioAD)
</div>
<div class="form-group">
@Html.LabelFor(model => model.Email)
<div class="input-group">
<span class="input-group-addon">@</span>
@Html.TextBoxFor(model => model.Email, new { @class = "form-control", style = "width: 37%" })
@Html.ValidationMessageFor(model => model.Email)
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
@Html.LabelFor(model => model.Desenvolvedor) <strong>?</strong>
<div class="radio">
<label>
<input type="radio" name="radioDesenvolvedor" id="simD" value="True" checked>
Sim
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radioDesenvolvedor" id="naoD" value="False">
Não
</label>
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Externo) <strong>?</strong>
<div class="radio">
<label>
<input type="radio" name="radioExterno" id="simE" value="True" checked>
Sim
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radioExterno" id="naoE" value="False">
Não
</label>
</div>
</div>
</div>
</div>
<p>
<button class="btn btn btn-primary" type="submit">Criar</button>
<button class="btn btn btn-primary" type="button" onclick="history.go(-1)">Cancelar</button>
</p>
</fieldset>
}
</div>
</div>
My Controller:
public ActionResult Cadastrar()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Cadastrar(RecursoDominio recurso)
{
if (ModelState.IsValid)
{
appRecurso.Salvar(recurso);
return RedirectToAction("Index");
}
return View(recurso);
}