开发者

how to get selected index of html.dropdownlistfor

开发者 https://www.devze.com 2023-01-31 10:34 出处:网络
i have a dropdownlist: <%= Html.DropDownListFor(model => model.OperatingSystem, Model.OperatingSystemDropDownBowValues, new { style = \"width:142px; margin-left: 10px; font-size: 11px;\" })%>

i have a dropdownlist:

<%= Html.DropDownListFor(model => model.OperatingSystem, Model.OperatingSystemDropDownBowValues, new { style = "width:142px; margin-left: 10px; font-size: 11px;" })%>

is it possible to get index of some item? i need validate a form, if first (default = "Choose...") dropdownlist item is selected(not by user) then its 开发者_JS百科not way to save other form values.


Only if you compare the submitted value with the original list, or use JavaScript/JQuery on the submission.

Can you add the value of the "Choose..." option as an empty string?

If you can set the Value of the "Choose..." then you could pick up the value return of you dropdown element isnullorempty

The [Required] attribute should work with that being sumitted too.

Cheers

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号