Hossein Zahed

Web Developer, Entrepreneur, Software Educator

What’s new in .NET Standard 2.0

This release of .NET Standard now supports around 33K APIs, compare to 14K APIs supported by .NET Standard 1.x. The good thing is that majority of the APIs are from .NET Framework. This makes life easy to port code to .NET Standards. Below image gives you a summary of .NET Framework APIs which are now included in .NET Standard 2.0.

Read More

Comparison: ViewModel vs ViewData vs ViewBag vs TempData vs Session

#

ViewModel

ViewData

ViewBag

TempData

Session

1 Is a class. It is a model specific for rendering a view. Is a key-value dictionary derived from ViewDataDictionary. Is a Dynamic property. It is a wrapper around ViewData. Is a key-value dictionary derived from TempDataDictionary. Is a key-value dictionary derived from TempDataDictionary.
2 Strongly typed class. So, no need for type-casting. Un-typed. So, needs type-casting for complex data. Type casting is not required. Un-typed: Needs type-casting for complex data type. Un-typed: Needs type-casting and null checking.
3 Represents only the data from a model required for rendering the view. Used to pass data between controller and view. Used to pass data between controller and view. Used to pass data between requests. I.e. it helps to pass data from one controller to another controller. Used to store a small amount of data for the duration of the user visiting the website.
4 The lifespan is only for the current request. The lifespan is only for the current request. The lifespan is only for the current request. Lifespan is for the current and subsequent request. The lifespan of TempData can be increased beyond the first redirection using TempData.Keep() method. lifespan of a session persists till it is forcefully destroyed by the server or the user.
5 On redirection the ViewModel object will be destroyed. On redirection, the value in the ViewData becomes Null. On redirection, the value in the ViewData becomes Null. The data stored in TempData persists only during redirection. The data stored in Session persists during any number of redirection.
6 Provides compile-time error checking and Intellisense support. Does not provide compile-time error checking. Does not provide compile-time error checking. Does not provide compile-time error checking. Does not provide compile-time error checking.
7
Usage:

(a) Display data in a table with master child relationship.
(b) Reports with aggregate and summary.
(c) Paging data in a table.
(d) Flexible with very simple as well as highly complex data from multiple data-source.

Usage:

(a) To pass a list of data to render a drop down list.
(b) To pass small amount of data to be rendered in the view.
(c) Not ideal for complex data involving multiple data sources.

Usage:

(a) To pass a list of data to render a drop down list.
(b) To pass small amount of data to be rendered in the view.
(c) Not ideal for complex data involving multiple data sources.

Usage:

(a) Useful for storing one time messages like error message and validation messages.
(b) Used in scenarios to pass small data from one action to another action or one controller call to another controller call.

Usage:

(a) To check whether the user is logged in to the website.
(b) To store the user’s permission information.

 

Conclusion

  1. Use ViewModel instead of ViewData and ViewBag. As ViewModel provides compile time error checking and intellisense support in Visual Studio IDE, the code will be clean and less error prone.
  2. Use TempData for error handling. On capturing and exception or error, pass the error details using TempData to the error page, so as to render the appropriate error details.
  3. Use Session to check the user’s login status and permission level.

Visual Studio 15 (2017) will let developers install only the components they need

  1. Universal Windows Platform development
  2. Web development (incl. ASP.NET, TypeScript, Azure tooling)
  3. Windows desktop app development with C++
  4. Cross-platform mobile development with .NET (incl. Xamarin)
  5. .NET desktop application development
  6. Linux and IoT development with C++
  7. Cross-platform mobile development with Cordova
  8. Mobile app development with C++ (incl. Android, iOS)
  9. Office / SharePoint add-in development
  10. Python web development (incl. Django and Flask support)
  11. Data science and analytical applications (incl. R, F#, Python)
  12. Node.js development
  13. Cross-platform game development (incl. Unity)
  14. Native Windows game development (incl. DirectX)
  15. Data storage and processing (incl. SQL, Hadoop, Azure ML)
  16. Azure cloud services development and management
  17. Visual Studio extension development