Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • View Data in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 37
    Comment on it

    View Data in MVC is used to transfer data from controller to view.

     

    View Data is used to store objects in collection form.

     

    View Data is used to access single value or collection of values from the controller to view.

     

    View Data can be accessed in the View page using string as the key.

     

     //Controller Code
    
    public ActionResult Index()
    
    {
    
          List<string> Student = new List<string>();
    
          Student.Add("Jignesh");
    
          Student.Add("Tejas");
    
          Student.Add("Rakesh");
    
     
    
          ViewData["Student"] = Student;
    
          return View();
    
    }
    
    //page code
    
    <ul>
    
        <% foreach (var student in ViewData["Student"] as List<string>)
    
            { %>
    
        <li><%: student%></li>
    
        <% } %>
    
    </ul>

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: