Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a drop down and the problem is that when i use html helpers for dropdown it is not getting the DataText field but the Id of selected item which i am displaying on another page. Please take a look.

C#
<pre> @*<select name="DropDown" id="DropDown" class="ddl">
                        <option id="0">---Select----</option>
                        <option id="1">100</option>
                        <option id="2">200</option>
                        <option id="3">300</option>
                        <option id="4">400</option>
                        <option id="5">500</option>
                        <option id="6">800</option>
                        <option id="7">1000</option>
                        <option id="8">1200</option>
                        <option id="9">1500</option>
                        <option id="10">1800</option>
                        <option id="11">2000</option>
                        <option id="12">3000</option>
                  
                    </select>*
                    @Html.DropDownList("DropDown", new List<SelectListItem> {
                        new SelectListItem {Text = "100", Value="1"},
                        new SelectListItem {Text = "200", Value="2"},
                        new SelectListItem {Text = "300", Value="3"},
                        new SelectListItem {Text = "400", Value="4"},
                        new SelectListItem {Text = "500", Value="5"},
                        new SelectListItem {Text = "800", Value="6"},
                        new SelectListItem {Text = "1000", Value="7"},
                        new SelectListItem {Text = "1200", Value="8"},
                        new SelectListItem {Text = "1500", Value="9"},
                        new SelectListItem {Text = "1800", Value="10"},
                        new SelectListItem {Text = "2000", Value="11"},
                        new SelectListItem {Text = "3000", Value="11"},
                        
    }, "Select", new { @class = "ddl" , id="DropDown"})



when i checked the O/P they both are producing the same HTML but Html is getting Text of selected field while html helper is getting the Id.
I am accessing the Text in "Show action method" like this

ViewBag.DistanceOfSubstation = model.DropDown;


P.S. i could use the simple Html but the validations do not work with it.
Posted
Comments
lokopi.nagar 23-Jul-15 7:05am    
Any other way to approach it?

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