Sunday, December 30, 2018

what is the difference between viewdata viewbag tempdata and session

in this Asp.netMVCc tutorials explains Viewbag is used to shares the small amount of data from the controller to view. the Viewbag is a Dynamic type which means no need to typecasting and downcasting. the lifespan of Viewbag is the last current HTTP request.

Example :

 namespace Alltechgeeks.Controllers
  public class TestController  : Controller
       IList <Test> testList  = new List<Test>()
                                               new Test(){id=1, name="Murali"},
                                               new Test(){id=2, name="Sathwiq"},
                                               new Test(){id=3, name="Siri"},
                                               new Test(){id=4, name="Krishna"}
           public ActionResult Index()
                  Viewbag.totaltest   = testList.Count();
                   return View();



Go to Index.cshtml page consume the viewbag.totaltest in view

        Total Test : @Viewbag.totaltest

we can assign any number of values and properties to Viewbag.

                                               Asp.Net MVC  - Get Started

  1. MVC Tutorials- Get Started 
  2. Architecture
  3. First Application
  4. Folder Structure
  5. Controller
  7. Model
  8. Bundling
  9. View Bag
  10. Temp Data
  11. View Data
  12. Action Methods
  13. Action Selectors
  14. HTML Helpers
  15. Partial Views
  16. Layout View
  17. Filters
  18. Action Filters
  19. Validations
  20. Area
  21. What is Entity Framework and types  
  22. Creating Project in Database First Approach
  23. Creating Project in Code first approach
  24. Creating Project in Model Base First approach

What is VIewBag?
What is TempData?
What is ViewData?

No comments: