Hi,
In everything I've read in both the docs and the demos you use a separate controller for the Read and ValueMapper functions associated with the virtualized combobox. The code below is taken from teh virtualizationcontroller.cs in your demo. I am trying to use Razor exclusively and … in theory … I shouldn't need a separate controller class. However, the page I am trying to use the combobox on is the index.cshtml under areas\identity\pages\account\Manage.
The markup, taken from you demo, for the combo is as follows:
@(Html.Kendo().ComboBox()
.Name("orders")
.DataTextField("ShipName")
.DataValueField("OrderID")
.HtmlAttributes(new { style = "width:100%" })
.Template("#= OrderID # | For: #= ShipName #, #= ShipCountry #")
.Height(290)
.DataSource(source => {
source.Ajax()
.PageSize(80)
.Read("Virtualization_Read", "ComboBox");
})
.Virtual(v => v.ItemHeight(26).ValueMapper("valueMapper"))
)
Please notice the .Read("Virtualization_Read", "ComboBox"). It's my understanding that "ComboBox" is the controller. How would I point/route that to the razor cshtml.cs file? Right now, if I put the "controller" functions in the .cshtml.cs file they never get called and the combo remains empty. I assume this is because it's not in a controller.
Any guidance or samples would be great!
Thanks … Ed
public ActionResult Virtualization_Read([DataSourceRequest] DataSourceRequest request)
{
return Json(GetOrders().ToDataSourceResult(request));
}
public ActionResult Orders_ValueMapper(int[] values)
{
var indices = new List<int>();
if (values != null && values.Any())
{
var index = 0;
foreach (var order in GetOrders())
{
if (values.Contains(order.OrderID))
{
indices.Add(index);
}
index += 1;
}
}
return Json(indices);
}
private IEnumerable<OrderViewModel> GetOrders()
{
using (var northwind = GetContext())
{
return northwind.Orders.Select(order => new OrderViewModel
{
ContactName = order.Customer.ContactName,
Freight = order.Freight,
OrderDate = order.OrderDate,
ShippedDate = order.ShippedDate,
OrderID = order.OrderID,
ShipAddress = order.ShipAddress,
ShipCountry = order.ShipCountry,
ShipName = order.ShipName,
ShipCity = order.ShipCity,
EmployeeID = order.EmployeeID,
CustomerID = order.CustomerID
}).ToList();
}
}
}