Home/MVC/store array in viewbag and retrieving in the view

store array in viewbag and retrieving in the view

In this post, we will discuss about how to store the array in view bag and how to use them in view.


A simple Controller action which store the string array in the ViewBag and return to the view.

public ActionResult Index()
string[] Countries = {“India”, “US”,”Nepal” };
ViewBag.Countries = Countries;
return View();


<h2>List Of Cities</h2>
@foreach (string city in ViewBag.Countries) {



  1. Anonymous May 6, 2013 at 6:55 pm

    very pleased to be here.

  2. riparazione wifi grigio August 8, 2014 at 2:09 am

    I like your blog. Bookmarked.

  3. Stephen S September 30, 2014 at 10:02 am

    It is very helpful , thank a lot

  4. Kirsten Neighbour August 28, 2017 at 5:22 pm

    Hello Dear, are you genuinely visiting this site daily, if so after that you will absolutely obtain pleasant knowledge.

  5. denis June 25, 2018 at 2:48 pm

    How do you add ” ‘ ” char to the string?

Leave a Reply