asp.net - Create DropDownList in Razor Engine MVC -
i have page insert new row in table in database.one field foreign key parent in same table.so want drobdownlist user choosing parent. table definition :
id integer parentid_fk integer body varchar title varchar create page view :
@model mvcdrlaptop.models.education @{ layout = null; } <!doctype html> <html> <head> <title>create</title> </head> <body> <script src="@url.content("~/scripts/jquery-1.7.1.min.js")" type="text/javascript"></script> <script src="@url.content("~/scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@url.content("~/scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> @using (html.beginform()) { @html.validationsummary(true) <fieldset> <legend>education</legend> <div class="editor-label"> @html.labelfor(model => model.title) </div> <div class="editor-field"> @html.editorfor(model => model.title) @html.validationmessagefor(model => model.title) </div> <div class="editor-label"> @html.labelfor(model => model.text) </div> <div class="editor-field"> @html.editorfor(model => model.text) @html.validationmessagefor(model => model.text) </div> <div class="editor-field"> //here parentid_fk dropdownlist </div> <p> <input type="submit" value="create" /> </p> </fieldset> } <div> @html.actionlink("back list", "index") </div> </body> </html> so should write creating dropdownlist?
firstly values database.
controller:
ienumerable<selectlistitem> items = value in values select new selectlistitem { text = value.tostring(), value = value.tostring(), selected = value == selectedmovie, }; viewbag.movietype = items; view:
@html.dropdownlist("items")
Comments
Post a Comment