Define an anonymous object in the HtmlAttributes
argument as follows:
@Html.DropDownListFor(modelItem => item.EscolhaBanco, new SelectList(new List<Object>
{
new {value = 0, text = ""},
new {value = 1, text = "Bradesco"},
new {value = 2, text = "Santander"}
}, new { id = "IdDoMeuDropDownList" }))
EDIT
To pass the selected value to the Controller , you will have to use a <button>
instead of a ActionLink
. It would look like this:
@using (Html.BeginForm())
{
<td>
@Html.DropDownListFor(modelItem => item.EscolhaBanco, new SelectList(new List<Object>
{
new {value = 0, text = ""},
new {value = 1, text = "Bradesco"},
new {value = 2, text = "Santander"}
}, "value", "text", 0))
</td>
<input type="submit" value="Enviar" class="btn btn-default" />
}
I do not know if you have defined a ViewModel for this, but the correct one is to set the ViewModel and make View / p>
namespace MeuProjeto.ViewModels
{
public class EscolhaBancoViewModel
{
public int EscolhaBanco { get; set; }
}
}
View looks like this:
@model MeuProjeto.ViewModels.EscolhaBancoViewModel
@using (Html.BeginForm())
{
<td>
@Html.DropDownListFor(modelItem => item.EscolhaBanco, new SelectList(new List<Object>
{
new {value = 0, text = ""},
new {value = 1, text = "Bradesco"},
new {value = 2, text = "Santander"}
}, "value", "text", 0))
</td>
<input type="submit" value="Enviar" class="btn btn-default" />
}
And Controller :
public ActionResult MinhaAction(EscolhaBancoViewModel viewModel)
{
// O valor vai aparecer em viewModel.EscolhaBanco
}