I have a method that is returning a list of strings. I simply would like to display that list in a view as plain text.
Here\'s the list from the controller:<
You can do it as follows in the view,
@foreach (var item in @Model)
{
<li>@item.PropertName</li>
}
Your action method Service
should return a View
. After this change the return type of your Service() method from string
to List<string>
public List<string> Service()
{
//Some code..........
List<string> Dates = new List<string>();
foreach (var row in d.Rows)
{
Dates.Add(row[0]);
}
return Dates;
}
public ActionResult GAStatistics()
{
return View(Service());
}
After this reference the model in your View:
@model List<string>
@foreach (var element in Model)
{
<p>@Html.DisplayFor(m => element)</p>
}
In my example the ActionResult looks like this:
public ActionResult List()
{
List<string> Dates = new List<string>();
for (int i = 0; i < 20; i++)
{
Dates.Add(String.Format("String{0}", i));
}
return View(Dates);
}
Which resulted in the output: