0

私は nopCommerce 2.30 (MVC 3 Razor) と Telerik().Grid を使用する初心者です。私は現在働いています

Nop.Admin プロジェクトで、多くの機能を備えたフォームに Html.Telerik().Grid を作成しようとしています。

下の私のグリッド画像を見てください。

ここに画像の説明を入力

これらが特徴です。

  1. グリッド データは、ドロップダウン リストの選択された値をフィルター処理する必要があります。

  2. すべてのグリッド列で並べ替えが有効になっています。

  3. 最初の列ヘッダーには、複数選択用のチェックボックスが含まれています。

  4. グリッド ビューでは、列のコンテキスト メニューを有効にする必要があります。

以下の私のコードを見てください。

私の .cshtml ファイル

     <td>
        @(Html.Telerik().Grid<NotificationMailReminderModel>()
                    .Name("productvariants-grid")

                    .DataKeys(keys =>
                    {
                        keys.Add(pv => pv.Username);
                    })
                    .DataBinding(dataBinding =>
                        dataBinding.Ajax()
                                .Select("EmailReminderByEvent", "Customer")
                    )
                    .Columns(columns =>
                    {
                        columns.Bound(pv => pv.IsSelected)
                        .ClientTemplate("<input type='checkbox'  name='Id' value='<#= Id #>' />")
                        .HeaderTemplate(@<text><input type="checkbox" title="check all records" id="checkAllRecords" /></text>)
                        .Width(50)

                        .HeaderHtmlAttributes(new { style = "text-align:center" })
                        .HtmlAttributes(new { style = "text-align:center" });
                        columns.Bound(pv => pv.Username).ReadOnly().Width(250);
                        columns.Bound(pv => pv.Firstname).ReadOnly();
                        columns.Bound(pv => pv.Lastname).ReadOnly();
                    })
                            .ClientEvents(events => events.OnDataBinding("Grid_onDataBinding").OnError("Grid_onError").OnSubmitChanges("Grid_onSubmitChanges")
                            .OnRowDataBound("onRowDataBound"))
                    .Editable(editing => editing.Mode(GridEditMode.InCell))
                    .Pageable(settings => settings.PageSize(2).Position(GridPagerPosition.Both))
                    .Sortable(sorting => sorting.Enabled(true))
        )
        <script type="text/javascript">

            $(document).ready(function () {
                $('#search-products').click(function () {
                    var grid = $('#productvariants-grid').data('tGrid');
                    grid.currentPage = 1; //new search. Set page size to 1
                    grid.ajaxRequest();
                    return false;
                });
                $('#send-mail-reminder').click(function () {
                    var grid = $('#productvariants-grid').data('tGrid');
                    grid.ajaxRequest();
                    return false;
                });

                $('#grdCustomerEventRoleData #productvariants-grid table thead #checkAllRecords').click(function () {
                    $("#grdCustomerEventRoleData #productvariants-grid table tbody input:checkbox").attr("checked", this.checked);
                });
            });

            function Grid_onError(args) {
                if (args.textStatus == "modelstateerror" && args.modelState) {
                    var message = "Errors:\n";
                    $.each(args.modelState, function (key, value) {
                        if ('errors' in value) {
                            $.each(value.errors, function () {
                                message += this + "\n";
                            });
                        }
                    });
                    args.preventDefault();
                    alert(message);
                }
            }

            function Grid_onDataBinding(e) {
                var loadData = true;
                var grid = $(this).data('tGrid');

                if (loadData) {
                    var searchModel = {
                        Event: $('#select-event').val()
                    };
                    e.data = searchModel;
                }
            }

            function Grid_onSubmitChanges(e) {
                //TODO pass current search parameters

                //we can't pass search parameters in submit changes
                //that's why let's just clear search params
                //$('#@Html.FieldIdFor(model => model.Event)').val('');
                //$('#SearchCategoryId').val('0');
                //$('#SearchManufacturerId').val('0');
            }
        </script>
    </td>

私のコントローラーアクション

  public ActionResult EmailReminder()
    {
        if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
            return AccessDeniedView();

        var model = new NotificationMailReminderModels();

        model.Event = 0;

        List<Nop.Core.Domain.Catalog.Product> products = _productRepository.Table.Where(p => p.EventDate != null && p.EventDate >= DateTime.MinValue).OrderBy(o => o.Name).ToList();


        model.Events = products.Select(p => new System.Web.Mvc.SelectListItem
        {
            Text = p.Name.Trim(),
            Value = p.Id.ToString()
        }).ToList();

        return View(model);
    }

[HttpPost, GridAction(EnableCustomBinding = true)] public ActionResult EmailReminderByEvent(int[] Id, GridCommand コマンド, NotificationMailReminderModels モデル) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView();

        var gridModel = new GridModel();

        string vwSlEv = ViewBag.SelectedEvent;
        int selevent = 0;
        if (!string.IsNullOrEmpty(vwSlEv))
        {
            Int32.TryParse(vwSlEv, out selevent);
        }
        else
        {
            selevent = model.Event;
        }

        var csts = _customerEventRoleRepository.Table.Where(e => e.EventId == selevent).Select(cs => cs.CustomerId).Distinct().ToArray();

        var customers = _customerRepository.Table.Where(c => !string.IsNullOrEmpty(c.Username) && !string.IsNullOrEmpty(c.Email) && csts.Contains(c.Id)).ToList();

        var gridmodel = customers.Select(x =>
        {
            NotificationMailReminderModel not = new NotificationMailReminderModel();
            not.Id = x.Id;
            not.Username = x.Username;
            not.Firstname = x.CustomerAttributes.FirstName;
            not.Lastname = x.CustomerAttributes.LastName;

            return not;
        });



        var grddata = new PagedList<NotificationMailReminderModel>(gridmodel.ToList(), command.Page - 1, command.PageSize);

        gridModel.Data = grddata;

        gridModel.Total = grddata.TotalCount;

        return new JsonResult
        {
            Data = gridModel
        };
    }

私のグリッドでは、データ グリッドの並べ替えとフィルタリングが正常に機能します。しかし、ContextMenu を取得できません

Razor インテリジェンスで機能します。

選択した行をコントローラーの POST 関数に渡したいです。

ただし、選択した行をコントローラー関数に渡す方法。

助けてください。

4

1 に答える 1