Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my dropdown list which is working fine in create view. but in edit view this dropdown did not load object original values

@Html.DropDownListFor(model => model.FundingSource, new List<selectlistitem>
                {new SelectListItem {Text = "ADP", Value = "ADP"},
                 new SelectListItem {Text = "CG", Value = "CG"},
                 new SelectListItem {Text = "ADP(D)", Value = ADP(D)"},                   
                 new SelectListItem {Text = "Others", Value = "Others"}                         
               },--Select--,new {@class="form-control"})


What I have tried:

@Html.DropDownListFor(model => model.FundingSource, new List<SelectListItem>
                {new SelectListItem {Text = "ADP", Value = "ADP"},
                 new SelectListItem {Text = "CG", Value = "CG"},
                 new SelectListItem {Text = "ADP(D)", Value = ADP(D)"},                   
                 new SelectListItem {Text = "Others", Value = "Others"}                         
               }, --Select--,new {@class="form-control"})
Posted
Updated 20-May-17 20:10pm
v3
Comments
Zunayed Shahriar 21-May-17 1:30am    
Can you show me your Create and Edit methods?
Asif_Aziz 21-May-17 2:33am    
The issue is resolved
Asif_Aziz 21-May-17 2:34am    
I have added the solution

1 solution

@Html.DropDownListFor(model => model.FundingSource, new SelectList(new List<SelectListItem>
            {new SelectListItem {Text = "ADP", Value = "ADP"},
             new SelectListItem {Text = "CG", Value = "CG"},
             new SelectListItem {Text = "ADP(D)", Value = "ADP(D)"},
             new SelectListItem {Text = "Others", Value = "Others"}
           }, "Text", "Value", Model.FundingSource), "--Select--",new {@class="form-control"})
 
Share this answer
 
Comments
Zunayed Shahriar 21-May-17 5:15am    
Great! I've always generated dropdowns from backend whether it's static or dynamic.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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