I have a dropdown list and i am trying to populate my dorpdown list with the data from the database, for this i am using mvc so how do i write a method in controller and how do i write the jquery for that: This is what i implemented in my view;
@Html.DropDownListFor("")
This is what i can find for jquery:
$(document).ready(function()
{
$('#id_trial').click(function() {
alert("entered in trial button code");
$.ajax({
type: "GET",
source: "/ClassName/MethodName",
dataType: "json",
success: function (data) {
$.each(data.aaData,function(i,data)
{
alert(data.value+":"+data.text);
var div_data="<option value="+data.value+">"+data.text+"</option>";
alert(div_data);
$(div_data).appendTo('#ch_user1');
});
}
});
});
});
This is what i think might be a method in a controller:
public virtual JsonResult MethodName()
{
IList<Fund> funds = _fundManager.Search();
var list = from x in funds
select new { Id = x.Code, Name = x.Name };
return Json(list);
}
I dont know how to link all of them and make it work, ant help will be appreciated.