I am trying to do what seems like the simplest thing in the world, but it has me absolutely banging my head against the wall in frustration. I just need to pass a simple string array from a C# method in my Controller class to javascript code in my index view. That's it. Just pass a simple array. But damned if I can figure out how, or make any sense of any of the convoluted answers I've seen on the internet.
Here are the details (simplified):
My controller:
public class BobsController : Controller
{
// GET: Bobs
public ActionResult Index()
{
return View();
}
public ActionResult ReturnBobsStuff()
{
List<string> myList = new List<string> { "element1", "element2",
"element3", "element4",
"element5",
};
string[] myArray = myList.ToArray();
return View(myArray);
}
}
My view:
<script>
$(function () {
var JavascriptArray = ??;
});
</script>
The ?? is the problem, obviously.