Sunday, 15 March 2015

asp.net mvc - How to display images in dropdownlist using MVC/jQuery -



asp.net mvc - How to display images in dropdownlist using MVC/jQuery -

this question has reply here:

how add together images in select list 5 answers

i need display images in dropdownlist values loaded in controller not db. google alot , needs utilize plug-in. there other alternative accomplish functionality without plugin?

i know don't want utilize plugin but, read on!

there plugin called select2 provides extended functionality bootstrap-type dropdown lists. on select2 webpage there illustration loads movies using rotten-tomatoes api. entries include title, image , synopsis.

if @ page source can see how accomplish this.

this excerpt javascript function handles returned values, , wraps them in html markup before passing them dropdown list.

function movieformatresult(movie) { var markup = "<table class='movie-result'><tr>"; if (movie.posters !== undefined && movie.posters.thumbnail !== undefined) { markup += "<td class='movie-image'><img src='" + movie.posters.thumbnail + "'/></td>"; } markup += "<td class='movie-info'><div class='movie-title'>" + movie.title + "</div>"; if (movie.critics_consensus !== undefined) { markup += "<div class='movie-synopsis'>" + movie.critics_consensus + "</div>"; } else if (movie.synopsis !== undefined) { markup += "<div class='movie-synopsis'>" + movie.synopsis + "</div>"; } markup += "</td></tr></table>" homecoming markup; }

as can see each entry in own table , html, can insert images.

there jquery + ajax phone call method on controller. method should homecoming jsonresult jquery on view , in select2 illustration 2 javascript methods process serialized json, ready dropdown list handle.

jquery asp.net-mvc asp.net-mvc-3

No comments:

Post a Comment