Click here to Skip to main content
15,902,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys..How to access and display the selected value in dropdownlist in Asp.net MVC.


In controller:


List<int> li = new List<int>();
for (int i = 20; i < 50; i++)
{
li.Add(i);

}
ViewData["j"] = new SelectList(li);



C#
public class details
{
[DisplayName("Age")]
        public int age { get; set; }

}
Posted

Hi,

you need to use the Html.DropDownListFor.
 
Share this answer
 
C#
@Html.DropDownListFor{"Model.Id",new SelectListItem{@ViewBag,DataFieldId,DataFieldValue},"Show Caption Value",new{id="abc"}


This is sample code from which you get clear idea
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900