Controller:
public ActionResult Cadastrar()
{
ViewBag.officelist = new SelectList(new OfficeREP().ListarTodos(),
"id",
"estado"
);
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Cadastrar(OpportunityMOD opportunidade)
{
if (ModelState.IsValid)
{
var opportunity01 = new OpportunityREP();
opportunity01.Salvar(opportunidade);
TempData["mensagem"] = "Cadastro realizado com Sucesso!";
return RedirectToAction("Index");
}
return View(opportunidade);
}
Model
[DisplayName("Escritório")]
public string officeId { get; set; }
View
<div class="col-md-2">
@Html.LabelFor(model => model.officeId)
@Html.DropDownListFor(model => model.officeId,(SelectList)ViewBag.officeList, string.Empty, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.officeId, "", new { @class = "text-danger" })