Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
    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:
C#
[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:
Razor
      @{
        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":

HTML
@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:

C#
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

1 solution

Hi ,
Did you find Solution for your problem ?
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900