Skip to main content

Posts

Showing posts with the label MVC

Understanding Caching in Asp.Net MVC

ching is a most important aspect of high-performance web application. Caching provides a way of storing frequently accessed data and reusing that data. Practically, this is an effective way for improving web application’s performance. Advantage of Caching Reduce hosting server round-trips When content is cached at the client or in proxies, it cause minimum request to server. Reduce database server round-trips When content is cached at the web server, it can eliminate the database request. Reduce network traffic When content is cached at the client side, it it also reduce the network traffic. Avoid time-consumption for regenerating reusable content When reusable content is cached, it avoid the time consumption for regenerating reusable content. Improve performance Since cached content reduce round-trips, network traffic and avoid time consumption for regenerating reusable content which cause a boost in the performance. Key points about Caching Use cac...

ViewData vs ViewBag vs TempData vs Session

In ASP.NET MVC there are three ways - ViewData, ViewBag and TempData to pass data from controller to view and in next request. Like WebForm, you can also use Session to persist data during a user session. Now question is that when to use ViewData, VieBag, TempData and Session. Each of them has its own importance. In this article, I am trying to explain the differences among these four. ViewData ViewData is a dictionary object that is derived from ViewDataDictionary class. public ViewDataDictionary ViewData { get ; set ; } ViewData is a property of ControllerBase class. ViewData is used to pass data from controller to corresponding view. It’s life lies only during the current request. If redirection occurs then it’s value becomes null. It’s required typecasting for getting data and check for null values to avoid error. ViewBag ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0. Basically it is a wrapper arou...

MVC Questions and Answers Part 1

Q. What is the MVC pattern? A. MVC(Model View Controller) is an architectural pattern for building applications. ID separates the applications in 3 main component Model, View and Controller. Model is nothing but the domain object or data, View is the component which contains user interface and Controller do the processing or incoming requests. Q. What are the Disadvantages of MVC Pattern? A. Even if this pattern comes with a lot of advantages, there are distinct disadvantages too. Firstly, it is too complex to implement and is not suitable for smaller application; rather, implementing this pattern in such applications will have adverse effects in the application's performance and design.  Q. What is an Action Filter in MVC? A. In ASP.NET MVC, controllers define action methods that usually have a one-to-one relationship with possible user interactions, such as clicking a link or submitting a form. For example, when the user clicks a link, a request is routed to the designat...