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();
}
Ravi PatelRank #439 · 5.7K reputationPosted Nov 4, 2015, 8:57 PM EST
<%foreach(string i in (List)ViewData["countries"])
{%>
<%= i.Tostring(); %>
<%} %>
Munesh SharmaRank #174 · 13.9K reputationPosted Nov 4, 2015, 7:28 PM EST
Ravi PatelRank #439 · 5.7K reputationPosted Nov 4, 2015, 7:45 PM EST
@foreach(var countryname in @ViewData["countries"] as List) { @countryname } i hope this will help youRam Pradeep54 reputationPosted Nov 4, 2015, 7:47 PM EST
Ram Pradeep54 reputationPosted Nov 4, 2015, 7:57 PM EST
@i
Ram Pradeep54 reputationPosted Nov 4, 2015, 7:58 PM EST
@i
Ravi PatelRank #439 · 5.7K reputationPosted Nov 4, 2015, 8:29 PM EST
<%foreach(var i in ViewData["countries"] as List
{%>
<%= i %> // check here may be <% =i. propertiesname %>
<%}%>
Ram Pradeep54 reputationPosted Nov 4, 2015, 8:52 PM EST
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl
<%foreach(string i in (List
{%>
<% i.Tostring(); %>
<%} %>
i am getting blank page as output.
Ram Pradeep54 reputationPosted Nov 4, 2015, 9:03 PM EST
Ravi PatelRank #439 · 5.7K reputationPosted Nov 4, 2015, 9:18 PM EST
Ram Pradeep54 reputationPosted Nov 4, 2015, 9:21 PM EST
Ravi PatelRank #439 · 5.7K reputationPosted Nov 4, 2015, 9:27 PM EST
Ram Pradeep54 reputationPosted Nov 4, 2015, 9:29 PM EST
Ravi PatelRank #439 · 5.7K reputationPosted Nov 4, 2015, 9:37 PM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts