PCBWay

Question 1: What is ASP.Net MVC?

DRex Electronics

Answer: The ASP.NET MVC is a framework for developing web based application using general Model View Controller pattern in ASP.NET. It provides an alternative to ASP.NET Web Forms pattern. It is a very powerful and efficient way to separate the concern with in an application. The MVC pattern has following main components:

1. Model: The Model represents a set of classes that describes the data you are working with and business logic. It also defines the business rules for how the data can be changed and manipulated.

2. The View: The View transforms a model or models into UI. The view is responsible for displaying the data that is received from the controller as the result.

3. The Controller: The Controller is responsible for controlling the overall application logic and acts as a coordinator between the View and the Model.

Question 2: What is Razor?

Answer: Razor is a view engine. View engine is responsible for rendering the HTML view of the page to the browser. It is an advanced view engine, introduced with MVC3. Razor syntax are advanced, compact and easy to learn. By default ASP.NET MVC supports two view engines: ASPX and Razor.

Question 3: What is ViewData and ViewBag?

Answer: ViewBag and ViewData are two options which are used to pass information from controller to view in ASP.Net MVC. Both have short life.  Short life means value of both becomes null when redirection occurred. This is because their purpose is to provide communication between views and controllers.

Despite having these similarities both (ViewBag and ViewData) are two different things if we talk about the implementation of both. The differences are as follows:

1. If we analyze both implementation wise then we will find that ViewData is a dictionary data structure – Dictionary of Objects derived from ViewDataDictionary and accessible using strings as Keys to these values while ViewBag makes use of the dynamic features introduced in C#4.0 and is a dynamic property.

2. While accessing the values form ViewData , we need to typecast the values (datatypes) as they are stored as Objects in the ViewData dictionary but there is no such need if we are accessing the value in case of ViewBag.

3. In ViewBag we can set the value like this: ViewBag.Name = “Value”; and can access as follows:

@ViewBag.Name
While in case of ViewData the values can be set and accessed as follows:
Setting ViewData : ViewData[“Name”] = “Value”;
Accessing value : @ViewData[“Name”]

Question 4: In which assembly is the MVC framework defined?

Answer: System.Web.MVC

Question 5: What does Model, View and Controller represent in an MVC application?

Answer:

Model: Model represents the application data domain. In short the applications business logic is contained with in the model.

View: Views represent the user interface, with which the end users interact. In short the all the user interface logic is contained with in the UI.

Controller: Controller is the component that responds to user actions. Based on the user actions, the respective controller, work with the model, and selects a view to render that displays the user interface. The user input logic is contained with in the controller.

Question 6: What are the advantages of ASP.NET MVC?

Answer: There are various advantages of ASP.NE MVC. Some points are given below:

1. Clear separation of concern

2. Test driven development

3. SEO friendly RESTful URL by design (This is now possible in ASP.NET 4 as well)

4. No viewstate

5. No postback events

6. Full control over rendered HTML

7. Rich UI support (possible through client side JS libraries like jQuery UI and others). Telerik has released some controls for MVC which includes Grid control as well

8. Session, JS, Ajax works.  Validation is even more powerful with DataAnnotations and jquery.

9. Is MVC faster?  Yes by default because of lack of viewstate and clean markup.  But performance is subject and MVC by design is more performant that traditional ASP.NET webforms (though webforms can be made as fast as required.

10. Pluggable architecture

Question 7: Is it possible to share a view across multiple controllers?

Answer: Yes, It is very well possible. You can pass the name of the view that use want to use in the parameter.

public ActionResult YourAction()
{
return View(“YourViewName”);
}

Question 8: Where are the routing rules defined in an asp.net MVC application?

Answer: In Application_Start event in Global.asax

Question 9: What is the advantage of using ASP.NET routing?

Answer: MVC gives you great control over how URLs are mapped to your controllers. It gives you the ability to define your URLs in a human readable SEO (Search Engine Optimization) friendly fashion, to remap old URLs to new functionality and side-by-side utilizes classic ASP.NET sites inside of MVC. It also results in hiding what kind of page a user is calling and what environment we are working in. Most of the new websites are following this and it is important to understand that routing is not URL rewriting as routing will have customizations and many attachments towards request/response. it is important to understand that routing is not URL rewriting.

Question 10: What are the 3 things that are needed to specify a route?

Answer: The 3 things required to specify a route are:
1. URL Pattern: You can pass the variable data to the request handler without using a query string. This is done by including placeholders in a URL pattern.

2. Handler: This handler can be a physical file of 2 types such as a .aspx file or a controller class.

3. Name for the Route: This name is an optional thing.

Question 11: What is the use of the following default route?
{resource}.axd/{*pathInfo}

Answer: This route definition, prevent requests for the Web resource files such as WebResource.axd or ScriptResource.axd from being passed to a controller.

Question 12: What is the difference between adding routes, to a webforms application and to an mvc application?

Answer:  MapPageRoute() method of the RouteCollection class is used to add route to a webforms application, where as to add routes to an MVC application we use MapRoute() method.

Question 13: What are the 2 ways of adding constraints to a route?

Answer:

1. Use regular expressions
2. Use an object that implements IRouteConstraint interface

Question 14: What are the different types of filters, in an asp.net mvc application?

Answer: ASP.NET MVC supports following types of filters:

1. Authorization filters

2. Action Filters

3. Result Filters

4. Exception Filters

Question 15: Which filter executes first in an asp.net mvc application?

Answer: Authorization filter

Question 16: What filters are executed in the end?

Answer: Exception Filters

Question 17: What symbol would you use to denote, the start of a code block in aspx views?

Answer: <%= %>

Question 18: In razor syntax, what is the escape sequence character for @ symbol?

Answer: Another @ symbol

Question 19: What are the file extensions for razor views?

Answer:

1. .cshtml – For C# programming language

2. .vbhtml – For VB programming language

Question 20: How to persist data from one page to another page in ASP.Net application?

Answer: Following techniques can be used to pass data from one page to another:

1. Querystring

2. HTTPContext

3. Sessions

4. Cookies

5. Cross Page Postback

6. @PreviousPageType directive

Question 21: Is it possible to cancel filter execution?

Answer: Yes

Question 22: Is it possible to create a custom filter?

Answer: Yes

Question 23: How do you specify comments using razor syntax?

Answer: Razor syntax makes use of @* to indicate the beginning of a comment and *@ to indicate the end.

Question 24: Name of different return types of a controller action method?

Answer: There are 9 return types(base) of Action in MVC . We generally use ActionResult Class because it implement all of these.

1.ContentResult

2. EmptyResult

3. FileResult

4. HttpStatusCodeResult

5.JavaScriptResult

6.JsonResult

7.RedirectResult

8.RedirectToRouteResult

9.ViewResultBase

Question 25: What is JSON?

Answer: JSON or JavaScript Object Notation, is an open standard format that uses human readable text to transmit data objects consisting of attribute-value pairs. It is used primarily to transmit data between a server and web application, as an alternative to XML.

Question 26: What are the new features of MVC 3?

Answer: ASP.NET MVC 3 shipped just 10 months after MVC 2 in Jan 2011. Some of the top features in MVC 3 included:

  •  The Razor view engine.
  •  Support for .NET 4 Data Annotations.
  •  Improved model validation
  •  Better JavaScript support with unobtrusive JavaScript, jQuery Validation, and JSON binding.
  •  Greater control and flexibility with support for dependency resolution and global action filters.
  •  Use of NuGet to deliver software and manage dependencies throughout the platform.

Question 27: What are the new features of MVC 4?

Answer: The following are the top features of MVC 4:

  •  ASP.NET Web API.
  •  Enhancements to default project templates.
  •  Mobile project template using jQuery Mobile.
  •  Display Modes.
  •  Task support for Asynchronous Controllers.
  •  Bundling and minification.

Question 28: What is Unobtrusive JavaScript?

Answer: Unobtrusive JavaScript doesn’t mix JavaScript code with your page markup. For example, rather than hooking in via event attributes like onclick and onsubmit, the unobtrusive JavaScript attaches to elements by their ID or class, often based on the presence of other attributes (such as HTML5 data-attributes).

It’s got semantic meaning and all of it; the tag structure, element attributes and so on should have a precise meaning. Strewing JavaScript gunk across the page to facilitate interaction (I’m looking at you, -doPostBack!) harms the content of the document.

Question 29: What is AuthConfig.cs in MVC 4?

Answer: “AuthConfig.cs” is used for configuring security settings, including sites for OAuth login.

Question 30: What is BundleConfig.cs in MVC 4?

Answer: “BundleConfig.cs” in MVC4 is used for registering bundles which are used by the bundling and minification system. Several bundles are added by default, including jQuery, jQueryUI, jQuery validation, Modernizr, and default CSS references.

Question 31: What is FilterConfig.cs in MVC 4?

Answer: FilterConfig.cs is used to register global MVC filters. The only filter registered by default is the HandleErrorAttribute, but this is a great place to put other filter registrations.

Question 31: What is RouteConfig.cs in MVC 4?

Answer: “RouteConfig.cs” is used to configure routes.

Question 32: What is WebApiConfig.cs in MVC 4?

Answer: WebApiConfig.cs is used to register Web API routes, as well as set any additional Web API configuration settings.