I have two models:
public class ProfessorModels
{
public string FullName { get; set; }
public int ID { get; set; }
}
and
In your controller:
[HttpGet]
public virtual JsonResult LoadInfo()
{
var query = _repository.GetInformation(); //Here you return the data.
return Json(query, JsonRequestBehavior.AllowGet);
}
Then in your view:
Then you load the drop down using jQuery
function LoadInfo() {
$.getJSON("@Url.Action(MVC.ControllerName.MethodName())", null,
function (data) {
$("#info").empty();
$.each(data, function () {
$("#info").append($("").val(this.Id).text(this.Name));
});
});
}
This assumes that Id and Name are properties of your object. You could use ID and FullName depending on which drop down you're loading. I also use T4MVC to get the different method names.
Hope this helps,