In my previous blogs, we explored about MVC. You may please refer to the article.
In this blog, we will see how to bind a dropdown list with hard code values in MVC.
Bind Static values with a Dropdown list in MVC
Below is the code to bind @Html.DropDownList
in MVC with static values.
<div class="form-group">
@Html.Label("Technology")
@Html.DropDownList("–Select–", new List<SelectListItem>
{
new SelectListItem{ Text="MVC", Value = "MVC" },
new SelectListItem{ Text="WCF", Value = "WCF" },
new SelectListItem{ Text="Web API", Value = "API" }
})
</div>
Keep your eyes on SharePointCafe.Net for upcoming MVC blogs
You may like a few blogs on MVC-
- What is MVC Routing?
- How to bind drop-down list in ASP.Net MVC?
- Attribute Routing in MVC
- RenderBody() vs RenderSection()
- What is a ViewStart.cshtml file?