2X faster development
The ultimate ASP.NET MVC UI toolkit to boost your development speed.
You can refer to the following procedure to achieve this requirement.
Create ModelFirst, create model that contains texts field. Model public class ListData { public string texts { get; set; } } public static class ListDataModal { public static List<ListData> listTempSource = new List<ListData>(); public static List<ListData> setListDataSource() { listTempSource.Add(new ListData { texts = "Discover Music" }); listTempSource.Add(new ListData { texts = "Sales and Events" }); listTempSource.Add(new ListData { texts = "Categories" }); listTempSource.Add(new ListData { texts = "MP3 Albums" }); listTempSource.Add(new ListData { texts = "More in Music" }); return listTempSource; } public static void clearSource() { listTempSource.Clear(); } } Create ControllerThen, create controller and pass the datasource in the view. Controller using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Sample.Models; // refers to models namespace Sample.Controllers { public class HomeController : Controller { public ActionResult Index() { ListDataModal.clearSource(); //Avoids duplication of listview items from the model return View(ListDataModal.setListDataSource().ToList()); } } } Create ViewCreate view page to add the codes for rendering the listview by using the datasource created earlier. CSHTML @model List<ListData> @*Creates listview with datasource*@ @Html.EJMobile().ListView("locallistview").ShowHeader(true).HeaderTitle("ListView with DataSource").DataSource(Model).FieldSettings(f => { f.Text("texts"); })
OutputFigure 1: Listview |
2X faster development
The ultimate ASP.NET MVC UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.