View <select id="category" name="category"> @foreach (var item in Model.category) { <option@(item.Key == Model.categoryid ? new HtmlString(" selected=\"selected\"") : new HtmlString("")) value="@item.Key">@item.Value</option> } </select> Model public class ProductModel { public int categoryid { get; set; } public Dictionary<int, string> category { get; set; } }
<select id="category" name="category">
@foreach (var item in Model.category)
{
<option@(item.Key == Model.categoryid ? new HtmlString(" selected=\"selected\"") : new HtmlString("")) value="@item.Key">@item.Value</option>
}
</select>
Model
public class ProductModel
{
public int categoryid { get; set; }
public Dictionary<int, string> category { get; set; }
}