列表没有绑定到下拉列表? mvc4简单一个

时间:2014-04-12 11:34:06

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

我一直在处理数据表,我对控制器进行了AJAX调用,因此我可以从控制器端加载一个列表。

完全在这里发布:

当我传递静态数据时,我的下拉列表绑定有效,当我从下拉列表中选择某些内容时,Value正在返回,但我需要的是当选择国家/地区名称时应该来。

代码://静态数据正常工作

public ActionResult AjaxDataProvider1(JQueryDataTableParamModel param)
{
     List<string> people = new List<string>{
                           "London" ,
                           "Liverpool",
                           "Portsmouth",
                           "Surrey" 
                            };

     JavaScriptSerializer serializer = new JavaScriptSerializer();
     var pp = serializer.Serialize(people);
     return this.Json(pp, JsonRequestBehavior.AllowGet);
}

其他方式从数据库中获取数据并传递不起作用:

在模型类中:`公开列表(selectedlistitem)impinfo(); //这里没有错误

在控制器中:

public ActionResult AjaxDataProvider1(JQueryDataTableParamModel param)
{
    var data = new list<selectedlistitem>(); 
    modelentities meobj = new modelentities();

    //Here i am writing for-each loop and assigning text and 
    //value and finally storing it into 'data' 

    meobj.impinfo = data ;
    var people = meobj.impinfo(); // passsing my list with value , text .      
    JavaScriptSerializer serializer = new JavaScriptSerializer();
    var pp = serializer.Serialize(people);
    return this.Json(pp, JsonRequestBehavior.AllowGet);
}

我的代码观点:

<script  type="text/javascript">

    $(document).ready(function () {

        $.datepicker.regional[""].dateFormat = 'dd/mm/yy';
        $.datepicker.setDefaults($.datepicker.regional['']);

        var tab=  $('#myDataTable').dataTable({

            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": 'AjaxDataProvider',
            "bJQueryUI": true,
            "aoColumns": [
                                  {
                                      "sName": "ID",
                                      "bSearchable": false,
                                      "bSortable": false,
                                      "fnRender": function (oObj) {
                                          return '<a href=\"Details/' +
                                          oObj.aData[0] + '\">View</a>';
                                      }
                                  },
                                    { "sName": "COMPANY_NAME" },
                                    { "sName": "ADDRESS" },
                                    { "sName": "TOWN" }
            ]

        });

        tab.columnFilter({
            aoColumns: [null,
                null,
                null,
                { type: "date-range" }
            ]
        });

        tab.makeEditable({
            "aoColumns": [
                null,
                null,
                {
                indicator: 'Saving...',
                tooltip: 'Click to select town',
                loadtext: 'loading...',
                type: 'select',
                onblur: 'submit',
                loadurl: 'AjaxDataProvider1'
                //data: "{'London':'London','Liverpool':'Liverpool','Portsmouth':'Portsmouth','Edinburgh':'Edinburgh', 'Blackburn':'Blackburn','Kent':'Kent','Essex':'Essex','Oxon':'Oxon','Lothian':'Lothian','West Sussex':'West Sussex','Lanarkshire':'Lanarkshire','Birmingham':'Birmingham','East Sussex':'East Sussex','Surrey':'Surrey'}"
            }]
        });

    });

        </script>
}

<table id="myDataTable" class="display">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Company name</th>
                            <th>Town</th>
                            <th>Date Created</th>
                        </tr>


                        <tr>
                            <th>ID</th>
                            <th>Company name</th>
                            <th>DATE FILTER :-></th>
                            <th>Date Created</th>
                        </tr>
                    <tbody> 
                   </tbody>

                </table>

此致

0 个答案:

没有答案