0

我是 asp.net mvc 的新手。
我能够在 mvc 中显示弹出窗口。
http://www.dotnet-tricks.com/Tutorial/mvc/42R0171112-CRUD-Operations-using-jQuery-dialog-and-Entity-Framework---MVC-Razor.html

我能够在 mvc 的下拉列表中加载数据。
但是,我想在下拉列表中加载数据,这些数据存在于弹出窗口中,所以该怎么做。

或者我必须在显示之前将数据加载到下拉列表中,但这不是最好的方式,因为用户可能会或可能不会显示弹出窗口。

请建议。

4

1 回答 1

2
function openPopUp()
{
  // ur code to open the popup
   LoadDropDownContent(); 
}
function LoadDropDownContent()
{
     var url = $(this).data('url')// url of ur ActionResult;
        var data = //Any data u want to pass on 
        //get the timestamp
        var nocache = new Date().getTime();
        //add the timestamp as a paramter to avoid caching
        data['nocache'] = nocache;
        $.getJSON(url, data, function (items) {
            var ddl = $('#urdrpdownid');
            ddl.empty();
            ddl.append($('<option/>', { value: '', text: '--Selecteer--' }));
            $.each(items, function (index, item) {
                ddl.append($('<option/>', {
                    value: item.Value,
                    text: item.Text,
                    selected: item.Selected
                }));
            });
        }); 
}

控制器中的代码

public ActionResult GetItems()
{
     var dropdownitems = //ur BL/DAL function to retrieve the list of entity;
     var items = dropdownitems.Select(s => new SelectListItem { Text = s.ColName, Value = s.ColName}).AsEnumerable();
        return Json(items, JsonRequestBehavior.AllowGet);
}
于 2014-02-04T05:45:31.743 回答