I am using following code :
Controller code:
[HandleError]
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public JsonResult GetColumn(String item)
{
String s;
if (item == "select")
{
s = "";
return this.Json(s);
}
else
{
List<Folderid> list1 = Folderid.GetFolderid().ToList();
return this.Json(list1);
}
}
}
Class that populate item list :
public class Folderid
{
public string ICPartID { get; set; }
public string CountryName { get; set; }
public static List<Folderid> GetFolderid()
{
return new List<Folderid>
{
new Folderid {
ICPartID = "DeletedItems",
CountryName = "United-States"
},
new Folderid{
ICPartID = "Inbox",
CountryName = "United-States"
} ,
new Folderid{
ICPartID = "Outbox",
CountryName = "United-States"
} ,
new Folderid{
ICPartID = "SentItems",
CountryName = "United-States"
} ,
new Folderid{
ICPartID = "LostandFound",
CountryName = "United-States"
}
};
}
}
Global.asax code:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"GetColumn",
"GetColumn/{item}",
new { controller = "Home", action = "GetColumn", item = "" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
View (index.aspx) code:
<asp:Content ID="aboutContent" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
$(document).ready(function() {
$('#dropdownlist1name').change(function() {
$.getJSON("Getcolumn/" + $("dropdownlist1name > option:selected").attr("value"),
null,
function(data) { addCustomers(data); });
});
});
function addCustomers(data) {
// remove any existing item
$('#dropdownlist2name >option').remove();
var list = $("dropdownlist2name")[0];
// Loop over the returned collection
for (var i = 0; i < data.length; i++) {
var cust = data[i];
var option = new Option(cust.ICPartID, cust.ICPartID);
list.add(option);
};
};
</script>
<select id="dropdownlist1name" name="dropdownlist1name"><option value="select">select</option>
<option value="senderid">senderid</option>
</select>
<select id="dropdownlist2name" name="dropdownlist2name" style="display:none"></select><br /><br /><br />
</asp:Content>
Site.master code: add all reference inside header tag
<script type="text/javascript" src="../../Scripts/jquery-1.3.2.js"></script>
<script type="text/javascript" src="../../Scripts/jquery-1.3.2.min-vsdoc.js"></script>
<script type="text/javascript" src="../../Scripts/MicrosoftAjax.js"></script>
<script type="text/javascript" src="../../Scripts/MicrosoftMvcAjax.js"></script>
Here First Dropdownlist is static and jquery is filling second combo onchange of dropdownlist item.
Jquery is not running when get publish on IIS.
Please provide the solution .
Regards
sumit