Telerik下拉列表不会加载到网格类库中 [英] Telerik dropdownlist doesn't load in the grid class library

查看:68
本文介绍了Telerik下拉列表不会加载到网格类库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须创建一个nopCommerce插件来实现一些带有下拉列表的telerik gird作为可编辑行,问题是插件是类库,而不是ASP.NET MVC应用程序,路由是在RouteProvider中手动完成的.cs文件。所以我在这里给出了一个例子:http://demos.telerik.com/aspnet-mvc/razor/grid/clientedittemplates并且必须具有以下配置:

我的型号:

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>



和我的自定义视图DiscountsEditor.cshtml:




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)



我能说的是,telerik找不到我的局部视图DiscountsEditor.cshtml,因为项目是一个类库,路由值不一样,对于特定的项目,我必须使我的观点嵌入式资源所以我可以用全名调用它们,问题是我无法将Telerik Grid配置为使用来自其他地方的部分视图。



我试图使用自定义这样的模板:




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());



但是我在网格中放入一些信息之后加载模板而不是可编辑,如果我想编辑它下拉列表转换为TextBox,我不知道接下来该做什么,或者我是否可以使用另一个控制器但是从当前视图加载下拉列表而不是局部视图。



谢谢。


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.

推荐答案

(e.form).find(' #Discounts')。data(' tDropDownList' ).select( function (dataItem){
return dataItem.Value == e.dataItem [' Text'];
});
}
< / 脚本 >
< table class = adminContent >
< tr >
< td class = adminTitle colspan = 2 >
DiscountBanner插件,用于在您的网站上实施单一和销售跟踪脚本
< / 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()。网格< 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(com mands =>
{
commands.Edit()。ButtonType(GridButtonType.Text);
commands.Delete()。ButtonType(GridButtonType.Text);
})。宽度(180)。标题(命令);
})
.ClientEvents(events => events.OnEdit(onEdit))
.EnableCustomBinding(true)

< / td >
< / tr >
< / table >
(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>



和我的自定义视图DiscountsEditor.cshtml:




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)



我能说的是,telerik找不到我的局部视图DiscountsEditor.cshtml,因为项目是一个类库,路由值不一样,对于特定的项目,我必须使我的观点嵌入式资源所以我可以用全名调用它们,问题是我无法将Telerik Grid配置为使用来自其他地方的部分视图。



我试图使用自定义这样的模板:




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());



但是我在网格中放入一些信息之后加载模板而不是可编辑,如果我想编辑它下拉列表转换为TextBox,我不知道接下来该做什么,或者我是否可以使用另一个控制器但是从当前视图加载下拉列表而不是局部视图。



谢谢。


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.


您好,

您是否找到了解决问题的方法?
Hi ,
Did you find Solution for your problem ?


这篇关于Telerik下拉列表不会加载到网格类库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆