View Bag And Tempdata.pptx

AddiyAli 26 views 7 slides Dec 24, 2022
Slide 1
Slide 1 of 7
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7

About This Presentation

Mvc Topics


Slide Content

View Bag And Tempdata Asad Ali

VIEW BAG IN ASP.NET MVC View Bag is also used to transfer data from a controller to a view. View Bag exists only for the current request and becomes null if the request is redirected. View Bag is a dynamic property based on the dynamic features introduced in C# 4.0. View Bag does not require typecasting when you use complex data type.

VIEW BAG IN ASP.NET MVC The general syntax of ViewBag is as follows: ViewBag .<PropertyName> = <Value>; Where, Property: Is a String value that represents a property of ViewBag . Value: Is the value of the property of ViewBag, Value may be a String, object, list, array or a different type, such as int , char, float, double DateTime etc . Note: ViewBag does not provide compile time error checking. For Example- if you mis-spell keys you wouldn’t get any compile time errors. You get to know about the error only at runtime . ViewData and ViewBag can access each other data interchangeably.

TEMP DATA IN ASP.NET MVC TempData is a Dictionary object derived from the TempDataDictionary class . TempData stores data as key-value pairs. TempData[“ Var ”] = “ Addiy ” TempData value must be type cast before use. Check for null values to avoid runtime error . TempData allows passing data from the current request to the subsequent request during request redirection.

TEMP DATA IN ASP.NET MVC The general syntax of TempData is as follows: where, TempData [<Key>] = <Value>; Key : Is a String value to identify the object present in TempData. Value : Is the object present in TempData.

TEMP DATA IN ASP.NET MVC

TEMP DATA IN ASP.NET MVC TempData in ASP.NET MVC can be used to store temporary data which can be used in the subsequent request. TempData will be cleared out after the completion of a subsequent request . Call TempData.Keep () to keep all the values of TempData in a third request.