Wednesday, 1 June 2016

ViewBag Example



//Controller Code
public ActionResult Index()
{
      List<string> Student = new List<string>();
      Student.Add("Jignesh");
      Student.Add("Tejas");
      Student.Add("Rakesh");

      ViewBag.Student = Student;
      return View();
//page code
<ul>
    <% foreach (var student in ViewBag.Student)
        { %>
    <li><%: student%></li>
    <% } %>
</ul>

No comments:

Post a Comment