[HttpGet] public virtual JsonResult LoadInfo() { var query = _repository.GetInformation(); //Here you return the data. return Json(query, JsonRequestBehavior.AllowGet); }
Then in your view:
<select id="info"></select>
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($("<option />").val(this.Id).text(this.Name)); }); }); }
This assumes that Id and Name are properties of your object. You could use ID and Name depending on which drop down you're loading.
Hope this helps,
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
function LoadInfo() {$.getJSON("@Url.Action(MVC.ControllerName.MethodName())", null,
function (data) {
$("#info").empty();
$.each(data, function () {
$("#info").append($("<option />").val(this.Id).text(this.Name));
});
});
}