English speaking and learning Interview Questions and Answers Programs C# Concept OOPS Concept JOBS

Sunday, July 30, 2017

ASP.NET MVC Interview Questions and Answers 3

Question 1 -Explain the advantages of ASP.Net MVC over ASP.NET?
Ans - 

  • 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.
  • Enables the full control over the rendered HTML.
  • Enables Test Driven Development (TDD).
  • Easy integration with JavaScript frameworks.
  • Following the design of stateless nature of the web.
  • RESTful urls that enables SEO.
  • No ViewState and PostBack events
Question 2 -What is Layout in ASP.Net MVC?
Ans - Layout pages are similar to master pages in traditional web forms. This is used to set the common look across multiple pages. In each child page we can find : 

Layout = "~/Views/Shared/TestLayout1.cshtml";

This indicates child page uses TestLayout1 page as it's master page.

Question 3 -Explain Sections is ASP.Net MVC?
Ans - Section are the part of HTML which is to be rendered in layout page. In Layout page we will use the below syntax for rendering the HTML :


And in child pages we are defining these sections as shown below :

@section TestSection{
<h1>Test Content<h1>

If any child page does not have this section defined then error will be thrown so to avoid that we can render the HTML like this :

@RenderSection("TestSection", required: false)

Question 4  -Explain the methods used to render the views in ASP.Net MVC?
Ans -Below are the methods used to render the views from action -

  • View() : To return the view from action.
  • PartialView() : To return the partial view from action.
  • RedirectToAction() : To Redirect to different action which can be in same controller or in different controller.
  • Redirect() : Similar to "Response.Redirect()" in webforms, used to redirect to specified URL.
  • RedirectToRoute() : Redirect to action from the specified URL but URL in the route table has been matched.

Question 5 -What is Dependency Injection in ASP.Net MVC?
Ans - it's a design pattern and is used for developing loosely couple code. This is greatly used in the software projects. This will reduce the coding in case of changes on project design so this is vastly used.
Dependency injection (DI) is a technique for achieving loose coupling between objects and their collaborators, or dependencies. Rather than directly instantiating collaborators, or using static references, the objects a class needs in order to perform its actions are provided to the class in some fashion. Most often, classes will declare their dependencies via their constructor, allowing them to follow the Explicit Dependencies Principle. This approach is known as "constructor injection".
When classes are designed with DI in mind, they are more loosely coupled because they do not have direct, hard-coded dependencies on their collaborators. This follows the Dependency Inversion Principle, which states that "high level modules should not depend on low level modules; both should depend on abstractions." Instead of referencing specific implementations, classes request abstractions (typically interfaces) which are provided to them when the class is constructed.

Below are the advantages of DI :

  • Reduces class coupling
  • Increases code reusing
  • Improves code maintainability
  • Improves application testing

You may also like

No comments :

Post a Comment