Q & A - Asp.Net MVC Questions & Answers

 

Q&A 1.

What are the Difference between ViewBag & ViewData?

ViewData is a dictionary of objects that is derived from ViewDataDictionary class and accessible using strings as keys.

ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0.

ViewData requires typecasting for complex data type and check for null values to avoid error.

ViewBag do not require typecasting for complex data type.

Q&A 2.

What are the new features of MVC 5?

Some of the new features of Asp.Net MVC5 are:

  1. Asp.Net Scaffolding
  2. ASP.NET Identity
  3. One ASP.NET
  4. Bootstrap in the MVC template
  5. Attribute Routing
  6. Filter Overrides
  7. Authentication Filters

Q&A 3.

How can we catch exception in Asp.Net MVC using custom filters?

We can create a custom exception filter to intercept and log unhandled exceptions.

In ASP.NET MVC 5 to intercept exceptions globally, the filter should be registered in GlobalFilterCollection using FilterConfig.cs file located in "~/App_Start/" folder.

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
 {
filters.Add(new CustomHandleErrorAttribute());

}

Q&A 4.

What is the most appropriate lifetime of database connection or ORM context in Asp.Net MVC application?

The lifetime should be the same as the request, because usually requests don’t live very long. Where it’s possible to wrap the whole request in one transaction, this can help comply with ACID principles.

Q&A 5.

Do we have ViewState in MVC?

This is a very commonly asked question by interviewers. MVC does not have viewstate is because viewstate is stored in a hidden field on the page.So this increases the size of the page significantly and impacts the page load time.

Q&A 6.

Explain the flow of MVC application.

MVC application flow is like UrlRoutingModule searches the routes defined in the routes table. When a matching pattern for the requested URL is found, then an object of controller class is created, and corresponding controller and action method is called. Controller queries or updates the model and returns the view.

  • Routing
  • Request interception by URLRoutingModule
  • MVC handler execution
  • Controller execution
  • Render view method execution

Q&A 7.

What is Model Binding?

In your action methods you need to retrieve data from the request and use that data.Model binding in MVC maps the data from the HTTP Request to the action method parameters.The repetitive task of retrieving data from the HTTPRequest is removed from the action method.This allows the code in the action method to focus only on the logic.

Q&A 8.

What is Area?

A large MVC application can consist of lots of controller, view and models. This makes the application difficult to manage. To manage the complexity of large MVC application we can group the application in different areas based on the functionality.

For example an eCommerce application can consist of many modules like user registration, product management and billing.

Q&A 9.

What is a View Engine?

View Engines are responsible for generating the HTML from the views. Views contains HTML and source code in programming language like a C#. View Engine generates HTML from the view which is returned to the browser.

Two main View Engines are WebForms and Razor ,each has its own syntax.
The default view engine of ASP.NET MVC is Razor. For C# code, it uses cshtml extension and for vb.net code, vbhtml extension.

Q&A 10.

What is MVC 6?

In MVC 6 ,the three frameworks,WebAPI ,MVC and SingnalR are merged into a single framework.Also in MVC dependency on System.Web is removed.


Related Quiz Content

x
This website is using cookies to make user experience of the site better. More info. OK