Dotnet interview questions for experienced-Part2

 

Part2
Dotnet questions for all levels like beginners and intermediate and advanced for 3 to 4 years experience following post will be useful.

1. What is MVC? what they represents and there advantages?

MVC is a architectural pattern it will be implemented in all languages. In .NET framework this is used by ASP.NET MVC Web Application.

M-Model- represents business logic

V- View - represents User Interface which will display the model data.

C-Controller - represents the User actions this will send response based on the request sent.

Advantages:

a. Multiple View Support

b. Light weight

c. Separation of concerns

d. Easy to test

e. Faster development


2. What is Partial View?

Partial View is a chunk of html which will be injected into DOM. It will be used in multiple Views. By using partial View we can reduce the redundancy of code.
Partial Views should be created in shared folder.
Syntax:
@Html.Partial("_Name")

3. What Keep() and Peek() in MVC?

Keep and peek are used to read the data from TempData. 

Example:

TempData["UserName"]= "Amarnath";

var value=TempData["UserName"];

after this line if we print @TempData["UserName"] will be null.

if we want to retain the value for next request then.

Peek():

var value1= TempData.Peek("UserName");

var value2=TempData["UserName"];

value2 will be their after reading value to value2 then TempData will be deleted.

This Peek return type is the value stored.

Keep():

var value3=TempData["UserName"];

TempData.Keep("UserName");

var value4=TempData["UserName"];

value2 will be their after reading value to value2 then TempData will be deleted.

This Keep return type is void.

4. What are the different ways we can use in MVC to pass data?

ViewData , ViewBag, TempData are used to pass data in ASP.NET MVC.

ViewData: 

     It is Dictionary type and need type cast and null check. used to pass data from Controller to View. 

ViewBag: 

     It is Dynamic type and no need of type cast and no null check. used to pass data from Controller to View.

TempData: 

     It is Session type and used to transfer data from view to controller, controller to view, or from one action method to another action method of the same or a different controller.
TempData stores the data temporarily and automatically removes it after retrieving a value.

5. What is MVC Routing?

we will have Routing table created from Route config after running application. So when ever a URL request sent to controller it will validate the URL with Routing table routes and request specific controllers related action method to provide the view corresponding to the request sent.

6. What are the return types in MVC?

we have 7 return types in MVC for action methods.

1. View Result
2. JSON Result
3. Content Result
4. File Result
5. JavaScript Result
6. Partial View Result
7. Empty Result

7. What are Action Filters in ASP.NET MVC ? How many are there?

Filters are used to execute some logic before or after the execution of an action Method.

There are mainly four filter:
Authorization filters – Implements the IAuthorizationFilter attribute.
Action filters – Implements the IActionFilter attribute.
Result filters – Implements the IResultFilter attribute.
Exception filters – Implements the IExceptionFilter attribute.

Exception filters will be executed at last.

8. What are the Validations in ASP. NET MVC?

We have both Client side validations and Server side validations/
Client side is handled by JavaScript or jQuery validations.
Server Side validations are implemented using System.ComponentModel.DataAnnotations

Types of Data Annotations in MVC.

1. Required
2. Range
3. StringLength
4. Datatype
5. DisplayName
6. MaxLength
7. Regular Expressions

9. What is the difference between RenderBody and RenderPage?

RenderBody method exists in the Layout page to render child page/view. It is just like the ContentPlaceHolder in master page. A layout page can have only one RenderBody method
Syntax:
@RenderBody()

RenderPage method also exists in the Layout page to render other page exists in your application. A layout page can have multiple RenderPage method.
Syntax:
@RenderPage("~/Views/Shared/_Header.cshtml")

10. What is View Engine in MVC?

MVC uses Razor View engine to render view into html.
By default, ASP.NET MVC support Web Form(ASPX) and Razor View Engine.
Razor is Lightweight.


Thank you for Reading.

This Series blogs link is below.


Post a Comment

0 Comments