Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET MVC Telerik
I'm must create a nopCommerce plugin to implement some telerik gird with a dropdownlist as editable rows, the problem is that the plugin is a Class Library, not a ASP.NET MVC application and the Routing is done manually in a RouteProvider.cs file. So I folowed the example here: http://demos.telerik.com/aspnet-mvc/razor/grid/clientedittemplates And must have the following configuration:
My Model:
    public class ContentModel : BaseNopModel
{
    public string ContentId { get; set; }
 
    [NopResourceDisplayName("Plugins.Widgets.DiscountBanner.Title")]
    public string Title { get; set; }
 
    [NopResourceDisplayName("Plugins.Widgets.DiscountBanner.Content")]
    public string Content { get; set; }
 
    [UIHint("DiscountsEditor"), Required]
    public string Discounts { get; set; }
}
My Controller:
[GridAction]
public ActionResult _SelectAjaxEditing()
{
    List<ContentModel> model = new List<ContentModel>();
    return View("Nop.Plugin.Widgets.DiscountBanner.Views.WidgetsDiscountBanner.Configure", _discountBannerSettings.contentGrid == "" || _discountBannerSettings.contentGrid == null ? new GridModel(model) : new GridModel(JsonHelper.JsonDeserialize<List<ContentModel>>(_discountBannerSettings.contentGrid)));
}
My View:
      @{
        Layout = "";
    }
    @model Nop.Plugin.Widgets.DiscountBanner.Models.ConfigurationModel
    @using Nop.Plugin.Widgets.DiscountBanner.Models;
    @using Nop.Web.Framework;
    @using Telerik.Web.Mvc.UI;
 
    @using Nop.Services.Discounts;
 
<script type="text/javascript">
    function onEdit(e) {
        $(e.form).find('#Discounts').data('tDropDownList').select(function (dataItem) {
            return dataItem.Value == e.dataItem['Text'];
        });
    }
    </script>
    <table class="adminContent">
    <tr>
        <td class="adminTitle" colspan="2">
            DiscountBanner Plugin for sing-up and sales tracking script implementation on your site
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
                @Html.NopLabelFor(model => model.ZoneId):
        </td>
        <td class="adminData">
                @Html.DropDownListFor(model => model.ZoneId, Model.AvailableZones)
                @Html.ValidationMessageFor(model => model.ZoneId)
        </td>
    </tr>
    <tr>
        <td class="adminTitle" colspan="2">
            @(Html.Telerik().Grid<ContentModel>()
            .DataKeys(keys =>
                {
                    keys.Add(model => model.ContentId);
                })
            .Name("discount-settings-grid")
            .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" }))
            .DataBinding(dataBinding =>
                {
                    dataBinding.Ajax()
                        .Select("_SelectAjaxEditing", "WidgetsDiscountBanner")
                        .Insert("_InsertAjaxEditing", "WidgetsDiscountBanner")
                        .Update("_SaveAjaxEditing", "WidgetsDiscountBanner")
                        .Delete("_DeleteAjaxEditing", "WidgetsDiscountBanner");
                }
            )
            .Columns(columns =>
                {
                    columns.Bound(c => c.Title);
                    columns.Bound(c => c.Content);
                    columns.Bound(c => c.Discounts);
 
                    columns.Command(commands =>
                        {
                            commands.Edit().ButtonType(GridButtonType.Text);
                            commands.Delete().ButtonType(GridButtonType.Text);
                        }).Width(180).Title("Commands");
                })
                .ClientEvents(events => events.OnEdit("onEdit"))
                .EnableCustomBinding(true)
             )
        </td>
    </tr>
</table>
And My custom View "DiscountsEditor.cshtml":
 
@using Telerik.Web.Mvc.UI;
@using Nop.Services.Discounts;
 
@{
    var _discountService = Nop.Core.Infrastructure.EngineContext.Current.Resolve<IDiscountService>();
    var discounts = _discountService.GetAllDiscounts(null, true);
    List<SelectListItem> listDiscounts = new List<SelectListItem>();
    foreach (var item in discounts)
    {
        listDiscounts.Add(new SelectListItem() { Text = item.Name, Value = item.Id.ToString() });
    }
}
@Html.Telerik().DropDownList().Name("Discounts").BindTo(listDiscounts)
From what could I tell is that telerik doesn't find my partial view DiscountsEditor.cshtml because the project is a class library and the route values are not the same, for the specific project I must make my views "Embedded Resource" so I can call them with the full name, the problem is that I can't configure Telerik Grid to use a partial view from somewhere else.
 
I tried to use a custom template like this:
 
columns.Bound(c => c.Discounts)
                        .ClientTemplate(
                        Html.Telerik().DropDownList().Name("Discount").BindTo(listDiscounts).ToHtmlString());
But the template loads after I put some information in the grid and is not editable, if I want to edit it the dropdownlist transforms into a TextBox, I don't know what to do next, or if I can use another controller but to load the dropdown from the current view not a partial view.
 
Thanks.
Posted 19-Jun-13 0:16am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi ,
Did you find Solution for your problem ?
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 24 Jan 2014
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