hi
see this code
<pre lang="xml">public JsonResult CityList()
{
string strXmlpath = Server.MapPath("~\\Models\\Location.xml");
var unit = from u in XDocument.Load(strXmlpath).Document.Descendants("Unit") select u;
List<SelectListItem> lst = new List<SelectListItem>();
foreach (var u in unit)
{
if (u.Attribute("ID").Value == "2")
{
var city = u.Elements("city");
foreach (var c in city)
lst.Add(new SelectListItem { Text = c.Attribute("Name").Value, Value = c.Attribute("ID").Value });
}
}
ViewData["cites"] = lst;
return Json(lst);
}
<script type="text/javascript">
$(document).ready(function () {
$(function () {
$.getJSON("/Home/CityList", function (data) {
var items = "<option>---------------------</option>";
$.each(data, function (i, country) {
items += "<option value='" + country.Value + "'>" + country.Text + "</option>";
});
$("#Countries").html(items);
});
});
</script>
<% using (Html.BeginForm()){%>
<label for="Countries">Countries</label>
<select id="Countries" name="Countries"></select>
<label for="States">States</label>
<select id="States" name="States"></select>
<% } %></pre>
but not show list cites in <selec></select>