mvc 5 dropdownlist
//To populate DropDownList using Viewbag, let's create some collection list with
//selectListItem types and assign to the Viewbag with appropriate name:
public ActionResult Index() {#
region ViewBag
List < SelectListItem > mySkills = new List < SelectListItem > () {
new SelectListItem {
Text = "ASP.NET MVC", Value = "1"
},
new SelectListItem {
Text = "ASP.NET WEB API", Value = "2"
},
new SelectListItem {
Text = "ENTITY FRAMEWORK", Value = "3"
},
new SelectListItem {
Text = "DOCUSIGN", Value = "4"
},
new SelectListItem {
Text = "ORCHARD CMS", Value = "5"
},
new SelectListItem {
Text = "JQUERY", Value = "6"
},
new SelectListItem {
Text = "ZENDESK", Value = "7"
},
new SelectListItem {
Text = "LINQ", Value = "8"
},
new SelectListItem {
Text = "C#", Value = "9"
},
new SelectListItem {
Text = "GOOGLE ANALYTICS", Value = "10"
},
};
ViewBag.MySkills = mySkills;#
endregion
return View();
}
//And now bind the ViewBag.MySkills values to DropDownlist as below code in view:
<tr>
<td> Populating With ViewBag Data </td>
<td> @Html.DropDownList("MySkills", (IEnumerable
<SelectListItem>)ViewBag.MySkills) </td>
</tr>
Are there any code examples left?
New code examples in category C#
-
C# 2022-03-27 22:40:23 c# movement script
-
C# 2022-03-27 22:15:17 Delete last modification on EntityFramework Core
-
C# 2022-03-27 22:15:02 file.create folder c#
-
C# 2022-03-27 19:25:04 Error inflating class android.support.constraint.ConstraintLayout
-
C# 2022-03-27 19:15:02 top down shooting in unity 2D
-
C# 2022-03-27 18:50:02 c# remove invalid directory characters
-
C# 2022-03-27 18:30:07 how to use K2 games Games parallax background
-
C# 2022-03-27 18:25:10 c# replace crlf
-
C# 2022-03-27 18:25:09 keycode for left mouse click unity