MVC 3 & JQuery - Insert an option item in the first position of a drop down list
I'm having trouble figuring this one out. In my view I have a dropdownlist populated like so.
<td colspan="4">@Html.DropDownListFor(m => m.email_list_id, new SelectList(EWS.Models.EmailList.GetAll(false), "email_list_id", "email_list_nm"), new { @class = "inputtext" })</td>
It populates fine. Also in the view I have this JQuery.
$('#email_list_id').append('<option value="">[Select Email List]</option>');
Which adds an option with a blank value and a prompt for the user. What I wo开发者_如何学JAVAuld like to do is insert this option as the first item rather than the last. Is there a way to do an insert as opposed to an append?
Try using prepend() instead of append() if you want to do it in jquery. Alternatively, you can add a blank element at the beginning of your list when you generate the list in your view.
精彩评论