2
How do I get a checkbox list like this:
<div class="editor-field" style="overflow-y: auto; height: 150px;">
<label>Especializações:</label>
@{
if (ViewBag.ListProfessionalSpecialization != null)
{
foreach (ProfessionalSpecialization item in (List<ProfessionalSpecialization>)ViewBag.ListProfessionalSpecialization)
{
<label style="display: inline">
<input type="checkbox" Value="@item.IdProfessionalSpecialization" name="ProfessionalSpecialization">
@Html.DisplayFor(modelItem => item.Title)
</label>
}
}
else
{
<label>O sistema não possue uma Especialização cadastrada. Finalize o cadastro e adicione uma nova especialização no seu painel de controle.</label>
}
}
</div>
I need to take the controller and save in the database the values in a table N to N. I need to save by ID.
my controller is as follows:
public ActionResult Create(FormCollection form)
{
var pUser = new ProfessionalUser()
{
IdProfessionalType = 1, //buscar o id na view
IdProfessionalSpecialization = 1, //buscar o id na view
IdProfessionalRegister = Convert.ToInt32(form["register"]),
Name = form["name"],
Password = form["password"],
Email = form["email"],
Phone = Convert.ToInt32(form["phone"]),
City = form["city"],
State = form["state"]
};
if (ModelState.IsValid)
{
using (ProfessionalUserDAO dao = new ProfessionalUserDAO())
{
if (dao.SaveProfessionalUser(pUser))
{
ViewBag.AlertMessage = "Profissional salvo com sucesso!";
return View();
}
}
}
ViewBag.AlertMessage = "Ocorreu um problema ao salvar!";
return View(pUser);
}