如何在nopcommerce中访问客户表格中的数据

时间:2016-10-22 06:02:40

标签: asp.net-mvc plugins nopcommerce

我想在管理页面中显示客户表格中nopcommerce的数据 我确实写了一个plugin并在控制器中接收数据,但在视图中我遇到了问题,并向我显示error happened消息。
这是我的controller代码:

  public class UserDetailsController : BasePluginController
{
    private ICustomerService _UserDetail;
    public UserDetailsController(ICustomerService UserDetail)
    {
        _UserDetail = UserDetail;
    }

    public ActionResult Manage()
    {
        return View();
    }

    [HttpPost]
    public ActionResult GetUsers(DataSourceRequest userDetail)
    {
        var details = _UserDetail.GetAllCustomers();
        var gridModel = new DataSourceResult
         {
             Data = details,
             Total = details.Count
         };
        return Json(gridModel);
    }
}

这是我的view代码:

   @{
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}


<script>
                $(document).ready(function() {
                    $("#user-details").kendoGrid({
                        dataSource: {
                            type: "json",
                            transport: {
                                read: {
                                    url: "@Html.Raw(Url.Action("GetUsers", "UserDetails"))",
                                    type: "POST",
                                    dataType: "json",

                                },
                            },
                            schema: {
                                data: "Data",
                                total: "Total",
                                errors: "Errors",
                                model: {
                                    id: "Id",
                                }
                            },
                            requestEnd: function(e) {
                                if (e.type == "update") {
                                    this.read();
                                }
                            },
                            error: function(e) {
                                display_kendoui_grid_error(e);
                                // Cancel the changes
                                this.cancelChanges();
                            },
                            serverPaging: true,
                            serverFiltering: true,
                            serverSorting: true
                        },
                        pageable: {
                            refresh: true,
                            numeric: false,
                            previousNext: false,
                            info:false
                        },
                        editable: {
                            confirmation: true,
                            mode: "inline"
                        },
                        scrollable: false,
                        columns: [
                            {
                                field: "Email",
                                title: "User Name",
                                width: 200
                            }, 

                            {
                                command: [
                                    {
                                        name: "edit",
                                        text: "@T("Admin.Common.Edit")"
                                    }, {
                                        name: "destroy",
                                        text: "@T("Admin.Common.Delete")"
                                    }
                                ],
                                width: 200
                            }
                        ]
                    });
                });
</script>




<div id="user-details"></div>

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

以这种方式更改GetUsers方法:

 var details = _UserDetail.GetAllCustomers();

      var gridModel = new DataSourceResult
      {
           Data=details.Select(x=>
           {
             return new UserDetail()
             {
                Email= x.Email
             };
          }),

       Total = details.Count(),
     };

   return Json(gridModel);