I am a beginner to MVC and now i would like to use Drop down in the form? i have tried using the Dropdownlistfor but it not working properly do we need any additional scripts for this.
Asked
Active
Viewed 52 times
-1
-
Are you working with Razor? – Timothy Groote Nov 20 '14 at 08:29
-
Please, show the code that you've tried to implement. Another solution is to manually build the dropdown list with – Vsevolod Goloviznin Nov 20 '14 at 08:31
-
http://www.asp.net/mvc/overview/older-versions/working-with-the-dropdownlist-box-and-jquery/using-the-dropdownlist-helper-with-aspnet-mvc – İsmet Alkan Nov 20 '14 at 08:43
-
[How to create a dropDown list in MVC4](http://stackoverflow.com/questions/26950614/how-to-create-a-dropdown-list-in-mvc4/26952781#26952781) – Nov 20 '14 at 11:07
2 Answers
0
does drop down has dynamic/Database value? Yes? As a first step, you need to have a model property which has the drop down values, something like
public List<States> StatesDDL
{ get; set;} // get the list of values here.
Static drop down? use the plain HTML
<select id="_ddlStates">
<option></option>...
</select>
good luck...

Ashwath
- 407
- 3
- 10
-
am not able to retrieve the value from the dropdownlist on to the page – jairam chakravarthi Nov 21 '14 at 05:50
-
use a jQuery selector. For Example - var ddlVal = $('#yourDDLName').val(); – Ashwath Nov 21 '14 at 08:26
0
In the the action method of your controller, you have to set a viewbag which is filled with list.
ViewBag.StudentID = new SelectList(db.Students, "StudentID", "Name");
And in the View just use the DropDownList Html Helper
@Html.DropDownList("StudentID", String.Empty)

Pratik Bhoir
- 2,074
- 7
- 19
- 36