Am I crazy or does this example not work?

3 posts, 0 answers
  1. Duke
    Duke avatar
    21 posts
    Member since:
    Dec 2016

    Posted 27 Mar Link to this post

    http://demos.telerik.com/aspnet-mvc/combobox/serverfiltering

    The view and the controller do not seem to work together.  The view is calling a controller action that does not exist, the controller action that does exist is not returning any data.

    Or if I'm wrong, I'll humbly accept corrections :-)

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1332 posts

    Posted 27 Mar Link to this post

    Hello Duke,

    The demo works, enter "ani" for example (note that the ComboBox' MinLength option is set to 3, thus for  filtering to be triggered a minimum of three characters need to be entered).
    As for the missing controller and action, in this particular demo the GetProducts action from the Home controller is called: 
    read.Action("GetProducts", "Home");

    This specific action is called by many other demos, but as you have correctly noticed it is not posted in the demo's source viewer. Currently the demos source viewer displays the view and the associated with it controller (in this case ServerFilteringController.cs), and since the actual server logic for filtering the ComboBox is in the Home controller it is not visible from this demo's page. This is definitely something that we aim at improving in the future in our demos site. The relevant code (views, controllers, etc.) should be displayed in the source section.

    Here's the actual definition of the GetProducts action:
    public JsonResult GetProducts(string text)
    {
        var northwind = new SampleEntities();
     
     
        var products = northwind.Products.Select(product => new ProductViewModel
        {
            ProductID = product.ProductID,
            ProductName = product.ProductName,
            UnitPrice = product.UnitPrice ?? 0,
            UnitsInStock = product.UnitsInStock ?? 0,
            UnitsOnOrder = product.UnitsOnOrder ?? 0,
            Discontinued = product.Discontinued
        });
     
        if (!string.IsNullOrEmpty(text))
        {
            products = products.Where(p => p.ProductName.Contains(text));
        }
     
        return Json(products, JsonRequestBehavior.AllowGet);
    }

    Since as I explained currently the demos site does not display all the relevant information, we can recommend running the sample demos application locally. It contains all the demos and comes with the Telerik UI for ASP.NET MVC installation. Here's a documentation article, which explains how you can run it. The sample application would allow you to inspect more closely the implementation of any demo that presents an interest.

    Regards,
    Ivan Danchev
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Duke
    Duke avatar
    21 posts
    Member since:
    Dec 2016

    Posted 27 Mar Link to this post

    Hey Ivan, thanks for the quick reply!

    You're right - the demo itself does work.  Sorry, I should have clarified:  I meant that the code in the source viewer doesn't work.  

    Thanks for the explanation about the source code.  Looking forward to seeing the (more) complete source code for these demos!

    Regards,

    Duke

Back to Top