0

我正在尝试将 DropDownBox 放入 Telerik MVC 网格中。我已经阅读了与此相关的所有答案,并在网上搜索了三天。我在这里不知所措,我一定在某处遗漏了一些简单的东西。我将在下面发布相关代码。

模型:

public class PriceListItemViewModel : IValidatableObject
{
        public string TaxLevelID
    { get; set; }

    //[UIHint("TaxLevels")]
    public string TaxLevelDescription
    { get; set; }

    public int TaxTypeID
    { get; set; }   

    //[UIHint("TaxTypes")]
    public string TaxTypeDescription
    { get; set; }
 }

控制器:

        public ActionResult EditTaxRecordEntryList(int? id)
    {
        ViewBag.TaxLevels = GetTaxLevels();
        ViewBag.TaxTpes = GetTaxTypes();
        PriceList taxRecordEntryList = RestRequest.Communicate<PriceList>("PriceMaintenanceService/PriceList/" + id, "GET");
        PriceListViewModel viewModel = AutoMapper.Mapper.Map<PriceList, PriceListViewModel>(taxRecordEntryList);
        return View(viewModel);
    }

    public List<SelectListItem> GetTaxTypes()
    {
        List<SelectListItem> selectList = new List<SelectListItem>();
        List<TaxType> taxTypes = RestRequest.Communicate<List<TaxType>>("PriceMaintenanceService/alltaxtypes", "GET");
        taxTypes.ForEach(o => selectList.Add(new SelectListItem
        {
            Text = o.Description,
            Value = o.ID,
            Selected = (taxTypes != null)
        }));

        return selectList;
    }

    public List<SelectListItem> GetTaxLevels()
    {
        List<SelectListItem> selectList = new List<SelectListItem>();
        List<TaxLevel> taxTypes = RestRequest.Communicate<List<TaxLevel>>("PriceMaintenanceService/alltaxlevels", "GET");
        taxTypes.ForEach(o => selectList.Add(new SelectListItem
        {
            Text = o.Description,
            Value = o.ID,
            Selected = (taxTypes != null)
        }));

        return selectList;
    }

看法:

 Html.Telerik().Grid(Model.PriceListItems)
    .Name("TaxRecordEntryList")
    .DataKeys(k => 
        k.Add(o => o.ID))
    .Columns(c =>
    {
        //c.Bound(o => o.TaxLevels).ClientTemplate("<#= TaxLevels #>");
        c.Bound(o => o.TaxLevelDescription).ClientTemplate(
            Html.Telerik().DropDownList()
            .Name("Tax Level")
            .BindTo(new SelectList(ViewBag.TaxLevels)));
        c.Bound(o => o.TaxTypeDescription).ClientTemplate("<#= TaxTypes #>");
        c.Bound(o => o.TaxRate).Title("Rate (1-100)%");
        c.Bound(o => o.EffectiveStartDate).Title("Start Date");
        c.Bound(o => o.EffectiveEndDate).Title("End Date");
        c.Command(commands =>
        {
            commands.Edit().ButtonType(GridButtonType.Image);
            commands.Delete().ButtonType(GridButtonType.Image);
        }).Title("Commands").HeaderHtmlAttributes(new { @style = "max-width:35px;" });
        c.Bound(o => o.TaxLevelID).Hidden(true);
        c.Bound(o => o.TaxTypeID).Hidden(true);
    })
    .DataBinding(binding => binding.Ajax()
        .Select("SelectPriceListItemsJson", "TaxRecord", new { PriceListID = Model.ID, priceType = "Tax" })
        .Update("UpdatePriceListItemsJson", "TaxRecord", new { PriceListID = Model.ID, priceType = "Tax" })
        .Insert("InsertPriceListItemsJson", "TaxRecord", new { PriceListID = Model.ID, priceType = "Tax" })
        .Delete("DeletePriceListItemsJson", "TaxRecord", new { PriceListID = Model.ID, priceType = "Tax" })
    )
    .Sortable()
    .ToolBar(tools =>
    {
        tools.Insert().ButtonType(GridButtonType.Image);
    })
    .ClientEvents(events => events
        .OnEdit("onEdit")
        .OnRowDataBound("OnRowDataBound") 
    )
    .Filterable(filtering => filtering.Enabled(true))

)

4

0 回答 0