Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
html code
XML
{{#locationDetails}}<select id="locationcity" > 
   <option selected="selected"  value="">{{allCities}}</option>
</select>{{/locationDetails}}


javascript

PHP
var LocationDetails = function (templateUrl, dataUrl) {
    $.get(templateUrl, function (template) {
        $.get(dataUrl, function (data) {
            var html = Mustache.to_html(template, data);
            $('#locationDetails').html(html);
        });
    });
}



in controller

C#
var locationDetails = new
      {       
          allCities=getAllCities
      };
      return Json(locationDetails,JsonRequestBehavior.AllowGet);


getAllCities has value of [0]:chennai,[1]:bangalore like that

i need to get value of arrays in option tag
Posted
Updated 22-Jul-14 0:52am
v3
Comments
ZurdoDev 22-Jul-14 9:58am    
Where are you stuck?
sagivasan 22-Jul-14 13:54pm    
<select id="locationcity" >
<option selected="selected" value="">{{allCities}}</option>
</select>

if i used like this am getting both the value "chennai" and "anna nagar" in same like "chennai,anna nagar" in the dropdown

but i need two <option> tag in select tag
one for chennai
another for annanagar
sagivasan 25-Jul-14 0:33am    
Found answer
ZurdoDev 25-Jul-14 7:05am    
Good to hear. Please post as solution so this no longer shows unanswered.

1 solution

JavaScript
function (templateUrl, dataUrl) {
    $.get(templateUrl, function (template) {
        $.ajax({
            type: "get",
            url: dataUrl,
            success: function (response, status) {
                var data = {
                    locationDetails:response.AllCities,
               };
                var html = Mustache.to_html(template, data);
                $("#locationDetails").html(html);
            },
            error: function (request, status, error) {
                alert(error);
            }
        });
    });
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900