Suffii Suffii - 29 days ago 5x
ASP.NET (C#) Question

Having Issue On Passing Array to View From Controller in Asp.Net MVC

I have a Controller action

which is listing all files in directory as:

public ActionResult Index()
string[] txtFiles = Directory.GetFiles(Server.MapPath("~/TextFiles/"));
return View(txtFiles);

and in
I have

@model List<txtFiles>
ViewBag.Title = "Index";


@foreach (var i in Model)
<li>@Html.ActionLink(System.IO.Path.GetFileName(i), "FileContent")</li>

but I am not sure what should I pass in
? I already tried
@model List<txtFiles>
but it didn't work and I am getting this error

enter image description here


You model is not a List<txtFiles> but a string[]

Change the model in your view.

@model List<txtFiles> should become @model string[] or @model IEnumerable<string>