加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 在nopcommerce 2.8中使用Telerik插件的自定义网

发布时间:2020-12-16 07:40:29 所属栏目:asp.Net 来源:网络整理
导读:我正在研究nopcommerce2.8版本.我有一个telerik插件实现的问题来创建新的网格. 我实施了一个概念,我希望为不同的客户提供不同价格的产品.因此,要为不同的客户分配新价格,请在管理面板中使用telerik在编辑产品变量页面中创建网格.我创建了一个新选项卡来显示
我正在研究nopcommerce2.8版本.我有一个telerik插件实现的问题来创建新的网格.
我实施了一个概念,我希望为不同的客户提供不同价格的产品.因此,要为不同的客户分配新价格,请在管理面板中使用telerik在编辑产品变量页面中创建网格.我创建了一个新选项卡来显示这些详细信息.我能够在网格中显示客户名称和价格,但是当我在编辑一行后点击更新按钮时,我无法调用更新功能.同样的更新功能我也要求删除网格行,所以当我点击删除相同的更新功能获取触发器.我认为在View中错过了一些设置.请帮我解决这个更新问题.

我的nopcommerce的模型,视图和控制器如下所示.

谢谢.

//Model
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using FluentValidation.Attributes;
using Nop.Admin.Models.Customers;
using Nop.Admin.Validators.Catalog;
using Nop.Web.Framework;
using Nop.Web.Framework.Localization;
using Nop.Web.Framework.Mvc;
using Telerik.Web.Mvc;

namespace Nop.Admin.Models.Catalog
{
    public partial class CustomerProductPriceModel : BaseNopModel
    {
        public int Customer_Id { get; set; }
        [NopResourceDisplayName("Customer Name")]
        public string Customer_name { get; set; }

        [NopResourceDisplayName("Price")]
        public decimal Price { get; set; }

        [NopResourceDisplayName("Unit")]
        public string Units { get; set; }

    }
}

// view

  @(Html.Telerik().Grid<CustomerProductPriceModel>()
        .Name("Grid")
        .DataKeys(x =>
                    {
                        x.Add(y => y.Customer_Id);
                    })
                     .DataBinding(dataBinding =>
                    {
                            dataBinding.Ajax()
                            .Select("CustomerProductPriceList","ProductVariant",new { productVariantId = Model.Id })
                            .Update("CustomerPriceUpdate",new { productVariantId = Model.Id })
                             .Delete("CustomerPriceUpdate",new { productVariantId = Model.Id });
                    })
        .Columns(columns =>
        {
            columns.Bound(y => y.Customer_name).Width(200).ReadOnly();
            columns.Bound(y => y.Price).Width(100);

            columns.Command(commands =>
            {
                commands.Edit().Text(T("Admin.Common.Edit").Text);
                commands.Delete().Text(T("Admin.Common.Delete").Text);
            }).Width(180);

        })
        .Editable(x =>
                {
                    x.Mode(GridEditMode.InLine);
                })
        .EnableCustomBinding(true)

      )


    // controller

    [GridAction(EnableCustomBinding = true)]
        public ActionResult CustomerPriceUpdate(GridCommand command,CustomerProductPriceModel model,int productVariantId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
                return AccessDeniedView();


             return CustomerProductPriceList(command,productVariantId);
        }


       [HttpPost,GridAction(EnableCustomBinding = true)]
        public ActionResult CustomerProductPriceList(GridCommand command,int productVariantId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
                return AccessDeniedView();

            var productVariant = _productService.GetProductVariantById(productVariantId);
            if (productVariant == null)
                throw new ArgumentException("No product variant found with the specified id");

            var CustomerPrices = PrepareCustomerProductPriceModel(productVariant.Product.Id);
            var CustomerPricesa = CustomerPrices
               .Select(x =>
               {
                   return new CustomerProductPriceModel()
                   {
                       Customer_Id = x.Customer_Id,Price = x.Price,Units = x.Units,Customer_name = x.Customer_name
                   };
               })
               .ToList();
            var model = new GridModel<CustomerProductPriceModel>
            {
                Data = CustomerPricesa,Total = CustomerPrices.Count
            };
            return new JsonResult
            {
                Data = model
            };
        }

解决方法

是否有理由不使用nopCommerce中已有的内置客户价格水平,或者您想一次显示所有价格?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读