[]
The quick start guides you through the steps of adding a ListBox control to your application. For information on how to add ASP.NET MVC Edition controls, see Adding Controls.
Follow the steps given below to get started. The example uses model Cities.cs added in the ComboBox QuickStart.
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.
Add a new Controller:
In the Solution Explorer, right click the folder Controllers.
From the context menu, select Add | Controller. The Add Scaffold dialog appears.
Complete the following steps in the Add Scaffold dialog:
Default1Controller
).A new controller is added to the application.
Replace the method Index()
with the following method.
public IActionResult Index()
{
return View();
}
Add a View for the controller:
Default1Controller
) to open it.Index()
.From the Solution Explorer, expand the folder Views.
Double click Index.cshtml
to open it.
Replace the default code of the Index.cshtml
file with the code given below to initialize a ListBox control.
@{
List<string> cities = Cities.GetCities();
}
<div>
<label>Select your city:</label>
</div>
<div id="list" style="width:200px;height:180px"></div>
<c1-list-box id="list" selected-index=0 >
<c1-items-source source-collection="@cities"></c1-items-source>
</c1-list-box>
type=note
Append the folder name and view name to the generated URL (for example: http://localhost:1234/Default1/index) in the address bar of the browser to see the view. Or link the view to the home page.