Hi I have been trying for the last hour to connect my c# backend to the front-end to output a list. I have always wondered what about the best way to pass data from backend to front-end.
In my scenario I only want to output a simple list from in mvc, but how do I send my list to the frontend so I can do something simple as outputting all the data in a table with something like a foreach:
foreach (var value in customerList) {
<p>value.Name</p>
}
I have looked at the solution suggested in this link: How to pass List from Controller to View in MVC 3. by archil
but I can’t figure out where to put protected internal ViewResult View( Object model )
So how can I output my list? I know the list contains content as I have put a breakpoint and stepped through it.
This is how my code looks like:
public List<Customer> customerList = new List<Customer>();
public ActionResult Index()
{
var client = new CustomerAzureAPIApp();
var response = client.Customer.Get();
var customers = response;
foreach (var customer in customers)
{
customerList.Add(customer);
}
return View();
}
I know I can use ViewBag, but I don’t want to create a new ViewBag for each item in the list, I would rather just send the whole list. Any suggestions?