Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC Telerik
Iam working on nopcommerce2.8 version. I have a problem with telerik plugin implementation to create new grid.
Iam implementing a concept where for a product i want to give different price for different customer. So to assign new price for different customers, in admin panel i am creating a grid in edit productvariant page using telerik. I have created a new tab to display these details. Iam able to display customer name and price in grid, but i am not able to call update function, when i click on update button after editing a row. I have created new model to save the customer and price details. Please help me to solve this update problem.
 
The model, view and controller of my nopcommerce in given below.
 
Thanks.
 

    //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", "ProductVariant", 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);
                }).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
                };
            }</customerproductpricemodel></customerproductpricemodel>
Posted 3-Apr-13 21:26pm
Edited 4-Apr-13 3:22am
(no name)150.8K
v2
Comments
Sandeep Mewara at 4-Apr-13 12:44pm
   
Looked at telerik forum?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 85
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 4 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100