@model TestDropdownList.Models.Person <script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script> @{ ViewBag.Title = "Index"; } <h2>Index</h2> @using (Html.BeginForm()) { @Html.LabelFor(x => x.CountryCode, "Country") @Html.DropDownListFor(x => x.CountryCode, new Dictionary<string, string>() { { "PH", "Philippines" }, { "CN", "China" }, { "CA", "Canada" }, { "JP", "Japan" } } .Select(x => new SelectListItem { Value = x.Key , Text = x.Value} ) ) } <script type="text/javascript"> $(function () { $('#CountryCode').change(function () { // alert('hello'); alert($(this).val() + ": " + $('option:selected', $(this)).text()); }); }); </script>
"Simplicity can't be bought later, it must be earned from the start" -- DB
Thursday, May 26, 2011
Dropdownlist callback using jQuery
Labels:
ASP.NET MVC,
jQuery,
Tweeting-Code
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment