TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mark Tabor
587
2k
460.5k
How to show the dropdown text value rather than id in mvc
Nov 24 2019 5:50 AM
I have a create view in which i have static dropdown list populated with some pre-defined values for the year , Now on listing i want to show the year text like 2012,2014,2019 rather than their values 1,2,3 How to achieve that remember i have static dropdown data is not coming from database below is the code
@Html.DropDownListFor(model=>item.Year_Passed, new List
{
new SelectListItem{ Text="Select Year", Value = "0" },
new SelectListItem{ Text="2000", Value = "1" },
new SelectListItem{ Text="2001", Value = "2" },
new SelectListItem{ Text="2002", Value = "3" },
new SelectListItem{ Text="2003", Value = "4" },
new SelectListItem{ Text="2004", Value = "5" },
new SelectListItem{ Text="2005", Value = "6" },
new SelectListItem{ Text="2006", Value = "7" },
new SelectListItem{ Text="2007", Value = "8" },
new SelectListItem{ Text="2008", Value = "9" },
new SelectListItem{ Text="2009", Value = "10" },
new SelectListItem{ Text="2010", Value = "11" },
new SelectListItem{ Text="2011", Value = "12" },
new SelectListItem{ Text="2012", Value = "13" },
new SelectListItem{ Text="2013", Value = "14" },
new SelectListItem{ Text="2014", Value = "15" },
new SelectListItem{ Text="2015", Value = "16" },
new SelectListItem{ Text="2016", Value = "17" },
new SelectListItem{ Text="2017", Value = "18" },
new SelectListItem{ Text="2018", Value = "19" },
new SelectListItem{ Text="2019", Value = "20" },
},
item.Year_Passed
, new { @class = "well well-sm", @id = "Year", @disabled = "disabled" })
item.YEar_passed is coming from Db it is saving year id value not text
Reply
Answers (
3
)
How to fix this error on chtml file to access your cs file?
MVC UserRegistration not launching nor showing any Layout