1
I wanted to put a dropdownlist
in my view where his List value went to the database, but I only know how to add values to DropDownlist
with data from a table, wanted to make a DropDownlist
with three values without having to create a new table and place in my View Razor.
Here’s an example of how I do in my views:
@model BlogWeb.ViewsModels.VisitaModel
@Html.ValidationMessage("DtIntegracao.Invalido")
@Html.ValidationMessageFor(v => v.Nome)
@Html.LabelFor(v => v.Nome, "Nome:")
@Html.TextBoxFor(a => a.Nome)
@Html.ValidationMessageFor(v => v.Rg)
@Html.LabelFor(v => v.Rg, "Rg:")
@Html.TextBoxFor(a => a.Rg)
@Html.ValidationMessageFor(v => v.DtIntegracao)
@Html.LabelFor(v => v.DtIntegracao, "Data Integração:")
@Html.TextBoxFor(v => v.DtIntegracao, "{0:dd-MM-yyyy}", new { Type = "date" })
@Html.ValidationMessageFor(v => v.ResponsavelId)
@Html.LabelFor(v => v.ResponsavelId, "Responsavel Entrada:")
@Html.DropDownListFor(v => v.ResponsavelId, new SelectList(ViewBag.Usuarios, "Id", "Nome"))