store array in viewbag and retrieving in the view

How to store array in viewbag and retrieving in the view using Razor

 

Kindly click here to know more detail about this post here. For more new posts kindly visit dotnet-helpers.com

Controller

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

View

<h2>List Of Cities</h2>
@foreach (string city in ViewData[“Countries”] as string[]) {
<li>@city
</li>
}

 

OUTPUT :

Kindly click here to know more detail about this post here. For more new posts kindly visit dotnet-helpers.com

 

Advertisements

3 thoughts on “store array in viewbag and retrieving in the view

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s