ASP.NET Core MVC Controls | ComponentOne
Working with Controls / Input Controls / ComboBox / Quick Start
In This Topic
    Quick Start
    In This Topic

    The quick start guides you through the steps of adding a ComboBox control to your MVC web application and add data to it. For information on how to add ASP.NET MVC Edition controls, see Adding Controls.

    Follow the steps given below to get started:

    ComboBox showing list of cities

    Create an MVC Application

    Create a new MVC application using the ComponentOne or VisualStudio templates. For more information about creating an MVC application, see Configuring your MVC Application topic.

    Create a Datasource for ComboBox

    1. Add a new class to the folder Models (for example: Cities.cs).
    2. Add the following code to the new model to define the classes that serve as a datasource for the ComboBox control.
      Cities
      Copy Code
      public class Cities
      {
          public static List<string> GetCities()
          {
              return new List<string>
              {
                  "Abidjan", "Accra", "Ahmedabad", "Alexandria", "Ankara", "Atlanta", "Baghdad", "Bandung", "Bangkok", "Barcelona", "Beijing", "Belo Horizonte",
          "Bengaluru", "Bogota", "Boston", "Buenos Aires", "Cairo", "Calcutta", "Chengdu", "Chennai", "Chicago", "Chongqung", "Dalian", "Dallas", "Delhi",
          "Detroit", "Dhaka", "Dongguan", "Essen", "Fuzhou", "Guadalajara", "Guangzhou", "Hangzhou", "Harbin", "Ho Chi Minh City", "Hong Kong", "Houston",
          "Hyderabad", "Istanbul", "Jakarta", "Johannesburg", "Karachi", "Khartoum", "Kinshasa", "Kuala Lumpur", "Lagos", "Lahore", "Lima", "London",
          "Los Angeles", "Luanda", "Madrid", "Manila", "Medellin", "Mexico City", "Miami", "Milan", "Monterrey", "Moscow", "Mumbai", "Nagoya", "Nanjing",
          "Naples", "New York", "Osaka", "Paris", "Pheonix", "Philadelphia", "Porto Alegre", "Pune", "Qingdao", "Quanzhou", "Recife", "Rio de Janeiro",
          "Riyadh", "Rome", "Saint Petersburg", "Salvador", "San Francisco", "Santiago", "Sao Paulo", "Seoul", "Shanghair", "Shenyang", "Shenzhen",
          "Singapore", "Surabaya", "Surat", "Suzhou", "Sydney", "Taipei", "Tehran", "Tianjin", "Toronto", "Washington", "Wuhan", "Xi'an-Xianyang", "Yangoon",
          "Zhengzhou", "Tokyo"
              };
          }
      }
      
    Back to Top

    Add a ComboBox control

    Complete the following steps to initialize an AutoComplete control.

    Add a new Controller

    1. In the Solution Explorer, right click the folder Controllers.
    2. From the context menu, select Add | Controller. The Add Scaffold dialog appears.
    3. Complete the following steps in the Add Scaffold dialog:
      1. Select Empty MVC Controller template.
      2. Set name of the controller (for example: Default1Controller).
      3. Click Add.
    4. Replace the method Index() with the following method.
      C#
      Copy Code
      public IActionResult Index()
      {
          return View();
      }
      

    Add a View for the Controller

    1. From the Solution Explorer, expand the folder Controllers and double click the controller QuickStartController to open it.
    2. Place the cursor inside the method QuickStart().
    3. Right click and select Add View. The Add View dialog appears.
    4. In the Add View dialog, verify that the view name is QuickStart and View engine is Razor (CSHTML).
    5. Click Add. A view is added for the controller.
    6. Instantiate a FlexChart control in the view QuickStart as shown below.
      HTML
      Copy Code
      @{List<string> cities = Cities.GetCities();}
      <div>
          <c1-combo-box selected-index=0 >
              <c1-items-source source-collection="@cities"></c1-items-source>
          </c1-combo-box>
      </div>
      

    Back to Top

    Build and Run the Project

    1. Click Build | Build Solution to build the project.
    2. Press F5 to run the project.
      Append the folder name and view name to the generated URL (for example: http://localhost:1234/QuickStart/QuickStart) in the address bar of the browser to see the view.
    Back to Top