I have a mvc application in vs 2010.in that i have a home controller with one method Index().It is going to return a list of countries.That countries list i want to display through view. How to do that in vs 2010.please tell me how to add view for this and what we need to write code for displaying it to end user.
Here is my controller action.
public ActionResult Index()
{
ViewData["countries"]= new List()
{
"INDIA",
"PAKISTHAN",
"AUSTRALIA",
"SOUTH AFRICA"
};
return View();
}
14 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ravi PatelPosted Nov 5, 2015, 1:57 AM
<%foreach(string i in (List)ViewData["countries"])
{%>
<%= i.Tostring(); %>
<%} %>
Ravi PatelPosted Nov 5, 2015, 2:37 AM
Ram PradeepPosted Nov 5, 2015, 2:29 AM
Ravi PatelPosted Nov 5, 2015, 2:27 AM
Ram PradeepPosted Nov 5, 2015, 2:21 AM
Ravi PatelPosted Nov 5, 2015, 2:18 AM
Ram PradeepPosted Nov 5, 2015, 2:03 AM
Ram PradeepPosted Nov 5, 2015, 1:52 AM
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl
<%foreach(string i in (List
{%>
<% i.Tostring(); %>
<%} %>
i am getting blank page as output.
Ravi PatelPosted Nov 5, 2015, 1:29 AM
<%foreach(var i in ViewData["countries"] as List
{%>
<%= i %> // check here may be <% =i. propertiesname %>
<%}%>
Ram PradeepPosted Nov 5, 2015, 12:58 AM
@i
Ram PradeepPosted Nov 5, 2015, 12:57 AM
@i
Ram PradeepPosted Nov 5, 2015, 12:47 AM
Ravi PatelPosted Nov 5, 2015, 12:45 AM
Munesh SharmaPosted Nov 5, 2015, 12:28 AM