After an extensive unsuccessful search I hope you guys can help me out here...
What I know: it is possible to generate tooltips for dropdownlist options through
<script type="text/javascript">
$(function () {
$("#someDropDownForList option").each(function () {
$(this).attr({ 'title': $(this).html() });
});
});
</script>
However, in my case I want to provide the users with more information on the options
<html>
<body>
<div>
@Html.DropDownListFor(
m => m.SomeModelProperty,
new selectList(Model.ListWithObjects, "Property1", "Property1"),
new { @id="someDropDownForList"})
</div>
</body>
</html>
How can I use jquery to use Property2 and Property3 to construct a tooltip text for each option?
Property1 + " has: " + Property2 + " and " Property3
With kind regards,
Paul
EDIT: a solution without jquery
<div>
<select id="someDropDownForList ">
@foreach(var item in Model.ListWithObjects)
{
<option title="Some property is the @item.Property2: with the @item.Property3">
@item.Property1
</option>
}
</select>
</div>
new SelectList()is the value of the<option>and the third is the text...var Property2 = '@Model.ListWithObjects[0].Property2', I am not able to replace the 0 with an index of sorts (like:var index = $(this).index();) though... any thoughts?Model.ListWithObjectsfrom client-side (javascript). You have to somehow output the data within the html. Best place would be to add some data attributes on<option>but theHtml.DropDownListhelper does not allow to customize the output for the<option>