c# 4.0 - JavaScript to choose droplist value not working in ASP .NET MVC4 with HTMLHelper and "All" -
i'm using javascript selected value of drop list in mvc 4 have issue think caused htmlhelper.
controller - populate droplist
private string populatestandard(object selectedvalue = null) { var query = db.database .sqlquery<standardmodel>( "select * [dbo].[getstandards] ('" + user.identity.name + "', '" + datetime.utcnow + "')") .tolist(); viewbag.standard = new selectlist(query, "standard", "standard", selectedvalue); try { return query[0].standard; } catch { return ""; } }
view
the view has section drop list. please note inclusion of "all". think problem. puts first row atop drop list saying "all" null value. want that. far (so what)
@html.displaynamefor(m => m.standard) @html.dropdownlist("standard", "all")
javascript
it's long story, have other code requires me value of drop list using javascript, i'm doing this:
var e = document.getelementbyid("standard"); var sstandard = e.options[e.selectedindex].value;
problem
if no value chosen, should first row, "all" text or "" value. instead, i'm getting second row, first 1 data populated database.
is html helper causing me not first row? or javascript off?
edit - show viewsource on drop list
these first few lines of rendered list
<select id="standard" name="standard"><option value="">all</option> <option value="2s">2s</option> <option value="aero">aero</option>
@html.dropdownlist("standard", "all")
here "all" option label. not value.
Comments
Post a Comment