Monday 13 February 2017

MVC interview questions Part 3

1. Ques: What are DataAnnotations in ASP.NET MVC ? List out the DataAnnotation Validator Attributes.
Answer:
Data Annotations used for validate the property of model classes. Data Annotation attribute classes are present in System.ComponentModel.DataAnnotations namespace.

DataType: It specify the datatype of a property.
DisplayName: It specify the display name for a property.
DisplayFormat: It specify the display format for a property like different format for Date proerty.
Required: It specify a property as required.
ReqularExpression: it validate the value of a property by specified regular expression pattern.
Range: It validate the value of a property with in a specified range of values.
StringLength:it specify minimum and maximum length for a string property.
MaxLength :it specify max length for a string property.
Bind :it specify fields to include or exclude when adding parameter or form values to model properties.

2. Ques: What is Action Methods in ASP.NET MVC?
Answer:
All the public methods of a Controller class which call from URL are Action methods.Action methods have a one-to-one mapping with user interactions and When a user enters a URL into the browser, the MVC application routing parse the URL and to determine the Action Methods of the controller and execute it.

3. Ques: What are different version of ASP.NET MVC?. And what are the feature inside them?
Answer:
ASP.NET MVC 1
it Runs on Visual Studio 2008(.Net 3.5)
MVC Pattern architecture with WebForm Engine.
Html Helpers.
Ajax helpers.
Routing.
Unit Testing.

ASP.NET MVC 2 
It Runs on Visual Studio 2010(.Net 3.5,& 4.0).
It support Strongly typed HTML helpers.
It support Templated Helpers.
It Support for DataAnnotations Attributes for validation on both client and server sides.
It Overriding the HTTP Method Verb including GET, PUT, POST, and DELETE ?
It Support Areas for partitioning of applications into modules.
It Support Asynchronous controllers.
It Support Binding Binary Data with Model Binders.
It Display Model-Level Errors.
It Support Binding Binary Data with Model Binders.

ASP.NET MVC 3
It Runs on .Net 4.0 and with Visual Studio 2010.
It has Ready made project templates.
It is HTML 5 enabled templates.
It Support for Multiple View Engines.
It Model Validation Improvements.
It is Integrated Scaffolding system.
HTML 5 enabled project templates.
It Support Dependency Injection and Global Action Filters.
It introduce new Razor View Engine.
It Support unobtrusive JavaScript, jQuery Validation, and JSON binding.

ASP.NET MVC 4
It Runs on .Net 4.0 with Visual Studio 2012.
ASP.NET Web API.
Refreshed and modernized default project templates.
New mobile project template.
Many new features to support mobile apps.
Enhanced support for asynchronous methods.
Bundling and minification.
Support for the Windows Azure SDK.
Mobile project template using jQuery Mobile.
Add Controller to other project folder.
It included the entity framework 5 database Migrations.
App_Start folder and separate classes.
Enabling Logins from Facebook and Other Sites Using OAuth and OpenID

ASP.NET MVC 5
It Runs on .Net 4.5 with Visual Studio 2013.
Attribute based routing.
Asp.Net Identity.
Bootstrap in the MVC template.
Authentication Filters.
Filter overrides.
ASP.NET Scaffolding.

ASP.NET MVC 6
Asp.net mvc and Web API has been merged in to one.
Dependency injection is inbuilt and part of MVC.
It Support Side by side - deploy the runtime and framework with your application
Everything packaged with NuGet, Including the .NET runtime itself.
It Support New JSON based project structure.
No need to recompile for every change. Just hit save and refresh the browser.
new Roslyn real-time compiler introduce.
vNext is Open Source via .NET Foundation and is taking public contributions.
vNext (and Rosyln) also runs on Mono, on both Mac and Linux today.

4. Ques: What is Area in ASP.NET MVC? What is advantage of it. 
Answer:
ASP.NET MVC create partition of Web applications into smaller units that is called areas.
Areas was introduced in Asp.net MVC2. Areas provide to separate a large MVC Web application into smaller functional groupings.It separate application into different functional sections like administration, customer support, Employee etc.Areas is very helpful in a large web application.Each MVC area has its own folder which contain controllers, views, and models.

Advantages:
Same mvc application multiple developers can work without interfere to each other.


5. Ques: Which are the important namespaces used in MVC ?
Answer:
  • System.Web.Mvc: It contains classes and interfaces that support the mvc web applications.The classes represent controllers, action results, views, partial views, and model binders etc.
  • System.Web.Mvc.Ajax: It contains classes that supports Ajax scripting in an asp.net mvc application.
  • System.Web.Mvc.Html: It contains classes that help render HTML controls in an mvc application.The classes represent forms, input controls, links, partial views, and validation etc.
  • System.Web.Mvc.Async: It contains classes that support asynchronous actions in an ASP.NET MVC application.

6. Ques: What is Dependency Resolution?
Answer:
MVC 3 introduced a new concept called a dependency resolver, which greatly simplified the use of dependency injection in your applications. This made it easier to decouple application components, making them more configurable and easier to test.
Support was added for the following scenarios:

  •       Controllers (registering and injecting controller factories, injecting controllers)
  •       Views (registering and injecting view engines, injecting dependencies into view pages)
  •       Action fi lters (locating and injecting fi lters)
  •       Model binders (registering and injecting)
  •       Model validation providers (registering and injecting)
  •       Model metadata providers (registering and injecting)
  •       Value providers (registering and injecting)



7. Ques: What is Html.ValidationSummary?
Answer:
ValidationSummary: The ValidationSummary helper method generates an unordered list of validation messages that are in the ModelStateDictionary object. The ValidationSummary can be used to display all the error messages for all the fields. It can also be used to display custom error messages. The Boolean parameter you are using (with a value of true) is telling the helper to exclude property-level errors. In other words, you are telling the summary to display only the errors in ModelState associated with the model itself, and exclude any errors associated with a specific model property. We will be displaying property-level errors separately.Assume you have the following code somewhere in the controller action rendering the edit view:
ModelState.AddModelError("", "This is all wrong!");
ModelState.AddModelError("Title", "What a terrible name!");
The first error is a model-level error, because you didn’t provide a key (or provided an empty key) to associate the error with a specific property. The second error you associated with the Title property, so in your view it will not display in the validation summary area (unless you remove the parameter to the helper method, or change the value to false). In this scenario, the helper renders the following HTML:


8. Ques: What are Scaffold template ?
Answer:
Answer:
These templates use the Visual Studio T4 templating system to generate a view based on the model type selected. Scaffolding in ASP.NET MVC can generate the boilerplate code we need for create, read, update,and delete (CRUD) functionality in an application. The scaffolding templates can examine the type definition for, and then generate a controller and the controller’s associated views. The scaffolding knows how to name controllers, how to name views, what code needs to go in each component, and where to place all these pieces in the project for the application to work.


9. Ques: What are the types of Scaffolding Templates?
Various types are as follows,
SCAFFOLD           DESCRIPTION

Empty                  Creates empty view. Only the model type is specified using the model syntax.

Create                  Creates a view with a form for creating new instances of the model.
                             Generates a label and input field for each property of the model type.

Delete                   Creates a view with a form for deleting existing instances of the model.
                             Displays a label and the current value for each property of the model.

Details                 Creates a view that displays a label and the value for each property of the
                             model type.

Edit                      Creates a view with a form for editing existing instances of the model.
                             Generates a label and input fi eld for each property of the model type.

List                      Creates a view with a table of model instances. Generates a column
                             for each property of the model type. 

No comments:

Post a Comment

Thank you for comment