Skip to main content

ASP .Net MVC

ASp .Net MVC



1. Explain MVC (Model-View-Controller) in general?

MVC (Model-View-Controller) is an architectural software pattern that basically decouples various components of a web application. By using MVC pattern, we can develop applications that are more flexible to changes without affecting the other components of our application.
§   “Model”, is basically domain data.
§   “View”, is user interface to render domain data.
§   “Controller”, translates user actions into appropriate operations performed on model.

2. What is ASP.NET MVC?

ASP.NET MVC is a web development framework from Microsoft that is based on MVC (Model-View-Controller) architectural design pattern. Microsoft has streamlined the development of MVC based applications using ASP.NET MVC framework.

3. Difference between ASP.NET MVC and ASP.NET WebForms?

ASP.NET Web Forms uses Page controller pattern approach for rendering layout, whereas ASP.NET MVC uses Front controller approach. In case of Page controller approach, every page has its own controller i.e. code-behind file that processes the request. On the other hand, in ASP.NET MVC, a common controller for all pages processes the requests.

4. What are the Core features of ASP.NET MVC?

Core features of ASP.NET MVC framework are:
§  Clear separation of application concerns (Presentation and Business Logic). It reduces complexity that makes it ideal for large scale applications where multiple teams are working.
§  It’s an extensible as well as pluggable framework. We can plug components and further customize them easily.
§  It provides extensive support for URL Routing that helps to make friendly URLs (means friendly for human as well as Search Engines).
§  It supports for Test Driven Development (TDD) approach. In ASP.NET WebForms, testing support is dependent on Web Server but ASP.NET MVC makes it independent of Web Server, database or any other classes.
§  Support for existing ASP.NET features like membership and roles, authentication and authorization, provider model and caching etc.

 

5. Can you please explain the request flow in ASP.NET MVC framework?

Request flow for ASP.NET MVC framework is as follows: Request hits the controller coming from client. Controller plays its role and decides which model to use in order to serve the request. Further passing that model to view which then transforms the model and generate an appropriate response that is rendered to client.

6. What is Routing in ASP.NET MVC?

In case of a typical ASP.NET application, incoming requests are mapped to physical files such as .aspx file. On the other hand, ASP.NET MVC framework uses friendly URLs that more easily describe user’s action but not mapped to physical files. Let’s see below URLs for both ASP.NET and ASP.NET MVC.
 ASP.NET MVC framework uses a routing engine, that maps URLs to controller classes. We can define routing rules for the engine, so that it can map incoming request URLs to appropriate controller. Practically, when a user types a URL in a browser window for an ASP.NET MVC application and presses “go” button, routing engine uses routing rules that are defined in Global.asax file in order to parse the URL and find out the path of corresponding controller.

7. What is the difference between ViewData, ViewBag and TempData?

In order to pass data from controller to view and in next subsequent request, ASP.NET MVC framework provides different options i.e. ViewData, ViewBag and TempData. Both ViewBag and ViewData are used to to communicate between controller and corresponding view. But this communication is only for server call, it becomes null if redirect occurs.
So, in short, its a mechanism to maintain state between controller and corresponding view. ViewData is a dictionary object while ViewBag is a dynamic property (a new C# 4.0 feature). ViewData being a dictionary object is accessible using strings as keys and also requires typecasting for complex types. On the other hand, ViewBag doesn’t have typecasting and null checks. TempData is also a dictionary object that stays for the time of an HTTP Request. So, Tempdata can be used to maintain data between redirects i.e from one controller to the other controller.

8. What are Action Methods in ASP.NET MVC?

As I already explained about request flow in ASP.NET MVC framework that request coming from client hits controller first. Actually MVC application determines the corresponding controller by using routing rules defined in Global.asax. And controllers have specific methods for each user actions. Each request coming to controller is for a specific Action Method.
Action methods perform certain operation using Model and return result back to View. As in above example, ShowBook is an action method that takes an Id as input, fetch specific book data and returns back to View as ViewResult. In ASP.NET MVC, we have many built-in ActionResults type:
§  ViewResult
§  PartialViewResult
§  RedirectResult
§  RedirectToRouteResult
§  ContentResult
§  JsonResult
§  EmptyResult
§  and many more….


9.Explain the role of Model in ASP.NET MVC?

One of the core feature of ASP.NET MVC is that it separates the input and UI logic from business logic. Role of Model in ASP.NET MVC is to contain all application logic including validation, business and data access logic except view i.e. input and controller i.e UI logic. Model is normally responsible for accessing data from some persistent medium like database and manipulate it

10.What are Action Filters in ASP.NET MVC?

If we need to apply some specific logic before or after action methods, we use action filters. We can apply these action filters to a controller or a specific controller action. Action filters are basically custom classes that provide a mean for adding pre-action or post-action behavior to controller actions.

What are the new features introduced in ASP.NET MVC5?

ASP.NET MVC5 was introduced with following exciting features:
§  Authentication Filters
§  Filter Overrides
§  Bootstrap
§  Attribute Routing

What is a ViewEngine in ASP.NET MVC?

“View Engine in ASP.NET MVC is used to translate our views to HTML and then render to browser.” There are few View Engines available for ASP.NET MVC but commonly used View Engines are Razor, Web Forms/ASPX, NHaml and Spark etc. Most of the developers are familiar with Web Forms View Engine (ASPX) and Razor View Engine.
§  Web Form View Engine was with ASP.NET MVC since beginning.
§  Razor View Engine was introduced later in MVC3.
§  NHaml is an open source view engine since 2007.
§  Spark is also an open source since 2008.

What is the difference between Razor View Engine and ASPX View Engine?


ASPX View Engine

Razor View Engine

WebForms View Engine uses namespace “System.Web.Mvc.WebFormViewEngine”.
“System.Web.Razor” is the namespace for Razor View Engine.
Comparatively fast.
A little bit slower than ASPX View Engine.
Nothing like Test Driven Development
Good support for Test Driven Development.
Syntax for ASPX View Engine is inherited from Web Forms pages as: <%= employee.FullName %>
Syntax for Razor View Engine is comparatively less and clean. @employee.FullName




Is it possible to remove the unused ViewEngine in ASP.NET MVC project?

Yes, it’s possible. As we know that by default two view engines are installed.
§  WebForm ViewEngine
§  Razor ViewEngine
If we are 100% sure that we are only going to use say ‘Razor ViewEngine’, and WebForm ViewEngine will remain idle/unused all the time, then we can remove the unused View engine by following the below simple steps:
1.    In our Gloabal.asax file, clear all the ViewEngines on Application_Start method.
2.    Add the specific one i.e Razor ViewEngine to our ViewEngine collection.

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());

What is a ViewModel in ASP.NET MVC?

A ViewModel basically acts as a single model object for multiple domain models, facilitating to have only one optimized object for View to render.
There are multiple scenarios where using ViewModel becomes obvious choice. For example:
§  Parent-Child View Scenario
§  Reports where often aggregated data required
§  Model object having lookup data
§  Dashboards displaying data from multiple sources

What are ASP.NET MVC HtmlHelpers?


ASP.NET MVC HtmlHelpers fulfills almost the same purpose as that of ASP.NET Web From Controls. For imlementation point of view, HtmlHelper basically is a method that returns a string ( i.e. an HTML string to render HTML tags). 

Comments

Popular posts from this blog

Gemini software Dot net interview question for experienced

Gemini Interview questions 4-8 year experienced Dot net professional Gemini Interview questions 4-8 year experienced Dot net professional 1,Asp .net mvc request life cycle. 2,How routing works 3,Where codes for routing are written 4,What is attribute based routing in aap.net Mvc 5,Is multiple routes possible on a single action method. 6,What is action filters. 7,what is authentication and authorization filters 8,What are the types of authentication 8,What is the use of data annotation 9,Can we fire data annotation in client side. 10,What is model binding 11,what are Html helpers

15 Essential jQuery Interview Questions

15 Essential jQuery Interview Questions 15 Essential jQuery Interview Questions 1,Explain what the following code will do: $( "div#first, div.first, ol#items > [name$='first']" ) Ans:This code performs a query to retrieve any element with the id first, plus all elements with the class first, plus all elements which are children of the element and whose name attribute ends with the string "first". This is an example of using multiple selectors at once. The function will return a jQuery object containing the results of the query. 2,What is wrong with this code, and how can it be fixed to work properly even with buttons that are added later dynamically? // define the click handler for all buttons $( "button" ).bind( "click", function() {     alert( "Button Clicked!" ) }); /* ... some time later ... */ // dynamically add another button to the page $( "html" ).append( " Click...