ASP.NET Interview Questions and Answers Set 6

51. What is ASP.MVC?

The ASP.NET MVC framework is a lightweight, highly testable presentation framework that is integrated with existing ASP.NET features, such as master pages and membership-based authentication. The MVC framework is defined in the System.Web.Mvc assembly.

52. Can you explain Model, Controller and View in MVC?

Model – It’s a business entity and it is used to represent the application data.

Controller – Request sent by the user always scatters through controller and it’s responsibility is to redirect to the specific view using View() method.

View – It’s the presentation layer of MVC.

53. Explain the new features added in version 4 of MVC (MVC4)?

Following are features added newly –

  • Mobile templates
  • Added ASP.NET Web API template for creating REST based services.
  • Asynchronous controller task support.
  • Bundling the java scripts.
  • Segregating the configs for MVC routing, Web API, Bundle etc.

54. Can you explain the page life cycle of MVC?

Below are the processed followed in the sequence –

  • App initialization
  • Routing
  • Instantiate and execute controller
  • Locate and invoke controller action
  • Instantiate and render view.

55. What are the advantages of MVC over ASP.NET?

  • Provides a clean separation of concerns among UI (Presentation layer), model (Transfer objects/Domain Objects/Entities) and Business Logic (Controller).
  • Easy to UNIT Test.
  • Improved reusability of model and views. We can have multiple views which can point to the same model and vice versa.
  • Improved structuring of the code.

56. What is Separation of Concerns in ASP.NET MVC?

It’s is the process of breaking the program into various distinct features which overlaps in functionality as little as possible. MVC pattern concerns on separating the content from presentation and data-processing from content.

57. What is Razor View Engine?

Razor is the first major update to render HTML in MVC 3. Razor was designed specifically for view engine syntax. Main focus of this would be to simplify and code-focused templating for HTML generation. Below is the sample of using Razor:

@model MvcMusicStore.Models.Customer

@{ViewBag.Title = “Get Customers”;}

<div class=”cust”> <h3><em>@Model.CustomerName</em> </h3>

58. What is the meaning of Unobtrusive JavaScript?

This is a general term that conveys a general philosophy, similar to the term REST (Representational State Transfer). Unobtrusive JavaScript doesn’t intermix JavaScript code in your page markup.

Eg : Instead of using events like onclick and onsubmit, the unobtrusive JavaScript attaches to elements by their ID or class based on the HTML5 data- attributes.

59. What is the use of ViewModel in MVC?

ViewModel is a plain class with properties, which is used to bind it to strongly typed view. ViewModel can have the validation rules defined for its properties using data annotations.

60. What you mean by Routing in MVC?

Routing is a pattern matching mechanism of incoming requests to the URL patterns which are registered in route table. Class – “UrlRoutingModule” is used for the same process