【问题标题】:loading data in dropdownlists in popup in mvc在 mvc 的弹出窗口中加载下拉列表中的数据
【发布时间】:2014-02-04 05:32:01
【问题描述】:

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

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

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

请提出建议。

【问题讨论】:

  • 加载弹出窗口后,您可以发出 Ajax 请求,该请求将返回 JSON,然后您可以将下拉列表与该 JSON 绑定...。如果您需要更多描述,请告诉我abt它..
  • 感谢您的指导,请发表您的描述,它会更有帮助
  • 如何显示弹出窗口?模态弹出??
  • 查看我的答案,了解另一种加载数据的方式。 stackoverflow.com/questions/21534325/…
  • @donstack - 如果这对您有用,请将其标记为答案。 :)

标签: jquery asp.net-mvc-4 modalpopup


【解决方案1】:
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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多