DropDownBox を Telerik MVC Grid に配置しようとしています。私はこれに関するすべての回答を読み、Web を検索して 3 日間続けました。私はここで途方に暮れています。どこか単純なものが欠けているに違いありません。以下に関連するコードを掲載します。
モデル:
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))
)