ASP.NET MVC ListBox - Server-Side API - Events

  • Alfreds FutterkisteALFKI
  • Antonio Moreno TaqueríaANATR
  • Around the HornAROUT
  • Berglunds snabbköpANTON
  • Berglunds snabbköpBERGS
  • Blauer See DelikatessenBLAUS
  • Blondesddsl père et filsBLONP
  • Bólido Comidas preparadasBOLID
  • Bon app'BONAP
  • Bottom-Dollar MarketsBOTTM
The ListBox control exposes the OnSelectedIndexChanged property which allows developers to specify the name of an action method which will be called when the selection is changed.
View - Aspx

    <% Html.Obout(new ListBox("ListBox1")
    {   
        OnSelectedIndexChanged = "ListBox/ApiserverEvents_SelectedIndexChanged"      
    }); %>
    
    <span ><%= ViewData["EventLogger"] %></span>
    
    
View - Razor

    @Html.Obout(new ListBox("ListBox1")
    {   
        OnSelectedIndexChanged = "ListBox/ApiserverEvents_SelectedIndexChanged"      
    })
    
    <span >@(ViewData["EventLogger"])</span>
    
    
Controller

    public ViewResult ApiserverEvents()
    {
        ViewData["ListBox1"] = GetCustomers();

        return View();
    }

    public ViewResult ApiserverEvents_SelectedIndexChanged(string ListBox1, string ListBox1_SelectedText)
    {
        ViewData["ListBox1"] = GetCustomers().Take(10);
        ViewData["EventLogger"] = "<br /><br /><b>The selection has been changed to:</b> " 
        + ListBox1_SelectedText;

        return View("ApiserverEvents");
    }