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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 40
    Comment on it

    Temp Data is dictionary which is used to store data into the controller to access it into the view.

     

    It stores data for a short period of time just like the session.

     

    It is mainly used to store one time message.

     

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

     

    Temp Data holds data between request and response.

     

    With the help of Keep method we can store the value of temp data even after request completion.

    .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: