Ejemplo 1: Cómo configurar el valor que se seleccionará en la lista desplegable en mvc
BY LOVE
• Here , Model is a dynamic object and from that modal we are fetching States property which is of list type.
• Here , employee is an employee object and from that object we are fetching state property of that particular employee.
@foreach (var S in Model.States)
{
if (S.StateName == employee.State)
{
<option value="@S.StateName" selected="selected">@S.StateName</option>
}
else
{
<option value="@S.StateName">@S.StateName</option>
}
}
Ejemplo 2: Cómo configurar el valor que se seleccionará en la lista desplegable en mvc
• Here , Model is a dynamic object and from that modal we are
fetching States property which is of list type.
• Here , employee is an employee object and from that object
we are fetching state property which is of string type.
@foreach (var S in Model.States)
{
if (S.StateName == employee.State)
{
<option value="@S.StateName" selected="selected">@S.StateName</option>
}
else
{
<option value="@S.StateName">@S.StateName</option>
}
}
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)