Question 1 -Explain the advantages of ASP.Net MVC over ASP.NET?
Ans -
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 :
@RenderSection("TestSection")
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 -
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 :
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
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 :
@RenderSection("TestSection")
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
C# Programs frequently asked in Interview
1)Abstraction and Encapsulation in OOPS
2)Inheritance in OOPS
3)Polymorphism in OOPS
4)Interface in OOPS
5)What is Virtual Function
6)What is Abstract class and Abstract function
7)What is Static Class and Static Members
8)What is Collections
9) What is Generics
10)What is Delegate
11)Exception Handling
12)Static Constructor
13)MultiThreading in C#
1)How to make a Registration Page using CAPTCHA in C#
2)How to make a Login Window in C# - Step by Step
3)How to make PhoneBook in C#
4)Insert,Update ,Delete in a C#
2)C# Interview Questions and Answers Part 2
1)Abstraction and Encapsulation in OOPS
2)Inheritance in OOPS
3)Polymorphism in OOPS
4)Interface in OOPS
5)What is Virtual Function
6)What is Abstract class and Abstract function
7)What is Static Class and Static Members
8)What is Collections
9) What is Generics
10)What is Delegate
11)Exception Handling
12)Static Constructor
13)MultiThreading in C#
2)How to make a Login Window in C# - Step by Step
3)How to make PhoneBook in C#
4)Insert,Update ,Delete in a C#
2)C# Interview Questions and Answers Part 2
No comments :
Post a Comment