1
I have the following difficulty.
My class addresses have the TipoEndereco
, wanted to mount a dropdownlist
Shall I set up a list on the controller? I got her in the view?
Thank you.
1
I have the following difficulty.
My class addresses have the TipoEndereco
, wanted to mount a dropdownlist
Shall I set up a list on the controller? I got her in the view?
Thank you.
1
With String gets like this:
@Html.DropDownListFor(model => model.TipoEndereco, new List<String> { "Residencial", "Comercial" }.Select(option => new SelectListItem
{
Text = option,
Value = option,
Selected = (Model != null) && (Model.TipoEndereco == option)
}), "Selecione...", new { @class = "form-control" })
Or you do it performatively and create an Enum:
public enum TipoEndereco
{
Residencial,
Comercial
}
And uses like this:
@Html.DropDownListFor(model => model.TipoEndereco, Enum.GetValues(typeof(TipoTelefone)).OfType<TipoEndereco>().Select(option => new SelectListItem
{
Text = option.ToString(),
Value = option.ToString(),
Selected = (Model != null) && (Model.TipoEndereco == option)
}), "Selecione...", new { @class = "form-control" })
Browser other questions tagged c# razor
You are not signed in. Login or sign up in order to post.
What do you have? This question can generate many results. Be more specific so we can help you.
– Grégori Sória
http://stackoverflow.com/questions/22346376/how-to-displaying-a-list-of-objects-in-mvc-view
– PauloHDSousa
TipoEndereco
is an Enum?– Leonel Sanches da Silva
No, string even @Ciganomorrisonmendez
– Furlan
Take a look at the link I sent @Furlan
– PauloHDSousa