我有一個方法返回一個字符串列表。我只是想以純文本的形式在視圖中顯示該列表。如何顯示MVC視圖中的對象列表?
這裏是從控制器列表:
public class ServiceController : Controller
{
public string Service()
{
//Some code..........
List<string> Dates = new List<string>();
foreach (var row in d.Rows)
{
Dates.Add(row[0]);
}
return Dates.ToString();
}
public ActionResult Service()
{
Service();
}
}
和視圖:
<table class="adminContent">
<tr>
<td>HEJ</td>
</tr>
<tr>
<td>@Html.Action("Service", "Service")</td>
</tr>
</tr>
</table>
我想我必須做的像一個foreach循環的觀點的東西,並引用列表使用「@」但是如何?
您可以檢查這個例子:http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music -store-part-3 –