hello,
I want to add ALL option in by dropdownlist code. Following is the code I am using to bind dropdown using Viewbag in mvc & dropdown data is coming from database
@Html.DropDownListFor(Model => Model.UserId, new SelectList(ViewBag.UserList, "Id", "Name", 0), "--Select Type--", new { @class = "form-control", @id = "ddlUser" })
i want first option should be ALL , so If user selects ALL option, I can save value 0 in database
thank you

Jignesh KumarRank #91 · 22.9K reputationPosted Nov 29, 2021, 10:29 PM EST
Please add option at 0 place in you list or viewbag public ActionResult Index() { #region ViewBag List mySkills = new List () { new SelectListItem { Text = "Select All", Value = "0" }, 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(); }Hi Shusant,
Please refer this article which will help you, refer this point "Populate a DropDownList using Viewbag"
https://www.c-sharpcorner.com/article/different-ways-bind-the-value-to-razor-dropdownlist-in-aspnet-mvc5/
Guest UserRank #2,192 · 643 reputationPosted Nov 30, 2021, 1:24 AM EST