In this article I will explain with an example, how to pass (send) String Array from Controller to View in ASP.Net MVC Razor.
The String Array will be passed (sent) from Controller to View as Model in ASP.Net MVC Razor.
The Controller consists of the following Action method.
Inside the Index Action method, the String Array is created and is sent to the View as Model.
public class HomeController : Controller
// GET: Home
public ActionResult Index()
string customers = new string;
customers = "John Hammond";
customers = "Mudassar Khan";
customers = "Suzzane Mathews";
customers = "Robert Schidner";
Inside the View, in the very first line, the String Array is specified as Model.
For displaying the records, an HTML Table is used. A loop will be executed over the Model which will generate the HTML Table rows with the items of the String Array.
Layout = null;
<meta name="viewport" content="width=device-width"/>
@foreach (string customer in Model)