Posts

Showing posts from January, 2016

Difference between array, arraylist, List, Hashtable, Dictionary and SortedList in c#

Basic difference is that arrays are of fixed size. Whereas an ArrayList implements the list data structure and can dynamically grow. While arrays would be more performance that a list, a list would be far more flexible since you don't need to know the required size initially. Array - represents an old-school memory array - kind of like a alias for a normal type[] array. Can enumerate. Can't grow automatically. I would assume very fast insertion, retrieve and speed. ArrayList - automatically growing array. Adds more overhead. Can enum., probably slower than a normal array but still pretty fast. These are used a lot in .NET List - one of my favorites - can be used with generics, so you can have a strongly typed array, e.g. List . Other than that, acts very much like ArrayList. Hashtable - plain old hashtable. O(1) to O(n) worst case. Can enumerate the value and keys properties, and do key/val pairs. Dictionary - same as above only strongly typed via generics, such a...

How do we make HTTP get and post calls in Angular?

To make HTTP calls we need to use the “$http” service of Angular. In order to use the http services you need to make provide the “$http” as a input in your function parameters as shown in the below code. function CustomerController($scope,$http) {  $scope.Add = function()  {             $http({ method: "GET", url: " http://localhost:8438/SomeMethod "     }).success(function (data, status, headers, config)   {                    // Here goes code after success   }  } } “$http” service API needs atleast three things:- •First what is the kind of call “POST” or “GET”. •Second the resource URL on which the action should happen. •Third we need to define the “success” function which will be executed once we get the response from the server. $http({ method: "GET", url: " http://localhost:8438/SomeM...

Explain $scope in AngularJs?

“$scope” is an object instance of a controller. “$scope” object instance get’s created when “ng-controller” directive is encountered. For example in the below code snippet we have two controllers “Function1” and “Function2”. In both the controllers we have a “ControllerName” variable. function Function1($scope) { $scope.ControllerName = "Function1";        } function Function2($scope) { $scope.ControllerName = "Function2"; } Now to attach the above controllers to HTML UI we need to use “ng-controller” directive. For instance you can see in the below code snippet how “ng-controller” directive attaches “function1” with “div1” tag and “function2” with “div2” tag. Instance of {{ControllerName}} created Instance of {{ControllerName}} created So this is what happens internally. Once the HTML DOM is created Angular parser starts running on the DOM and following are the sequence of events:- •The parser first finds “ng-controller” directive which is pointing t...

What are expressions in Angular?

Angular expressionsare unit of code which resolves to value. This code is written inside curly braces “{“. Below are some examples of angular expressions:- The below expression adds two constant values. Hide   Copy Code {{1+1}} The below expression multiplies quantity and cost to get the total value. Hide   Copy Code The value total cost is {{ quantity * cost }} The below expression displays a controller scoped variable. The value of Customer code is {{CustomerCode}} The value of Customer code is {{CustomerCode}}

What are controllers and need of ng-controller and ng-model in Angular?

“Controllers” are simple javascript function which provides data and logic to HTML UI. As the name says controller they control how data flows from the server to HTML UI. For example below is simple “Customer” controller which provides data via “CustomerName” and “CustomerCode” property and Add/ Update logic to save the data to database. function Customer($scope) {         $scope.CustomerName = "Shiv";         $scope.CustomerCode = "1001";         $scope.Add = function () {         }         $scope.Update = function () {         } } “ng-controller” is a directive.Controllers are attached to the HTML UI by using the “ng-controller” directive tag and the properties of the controller are attached by using “ng-model” directive. For example below is a simple HTML UI which is attached t...

Explain Directives in AngularJs

Directives are attributes decorated on the HTML elements. All directives start with the word “ng”. As the name says directive it directs Angular what to do. For example below is a simple “ng-model” directive which tells angular that the HTML textbox “txtCustomerName” has to be binded with the “CustomerName” property. Some of the most commonly used directives are ng-app,ng-controller and ng-repeat

What are controllers and need of ng-controller and ng-model in AngularJs?

“Controllers” are simple javascript function which provides data and logic to HTML UI. As the name says controller they control how data flows from the server to HTML UI. For example below is simple “Customer” controller which provides data via “CustomerName” and “CustomerCode” property and Add/ Update logic to save the data to database. function Customer($scope) {         $scope.CustomerName = "Shiv";         $scope.CustomerCode = "1001";         $scope.Add = function () {         }         $scope.Update = function () {         } } “ng-controller” is a directive.Controllers are attached to the HTML UI by using the “ng-controller” directive tag and the properties of the controller are attached by using “ng-model” directive. For example below is a simple HTML UI which is attached t...

Explain Directives in AngularJs?

Directives are attributes decorated on the HTML elements. All directives start with the word “ng”. As the name says directive it directs Angular what to do. For example below is a simple “ng-model” directive which tells angular that the HTML textbox “txtCustomerName” has to be binded with the “CustomerName” property. Hide  Some of the most commonly used directives are ng-app,ng-controller and ng-repeat

What are the 3 things that are needed to specify a route in mvc?

following are the 3 things that are needed to specify a route in mvc : 1. URL Pattern - You can include placeholders in a URL pattern so that variable data can be passed to the request handler without requiring a query string. 2. Handler - The handler can be a physical file such as an .aspx file or a controller class. 3. Name for the Route - Name is optional.

Name a few different return types of a controller action method?

The following are just a few return types of a controller action method. In general an action method can return an instance of a any class that derives from ActionResult class. 1. ViewResult 2. JavaScriptResult 3. RedirectResult 4. ContentResult 5. JsonResult

What are the advantages of ASP.NET MVC?

1. Extensive support for TDD. With asp.net MVC, views can also be very easily unit tested. 2. Complex applications can be easily managed 3. Seperation of concerns. Different aspects of the application can be divided into Model, View and Controller. 4. ASP.NET MVC views are light weight, as they donot use viewstate.

Can we have a Custom View Engine in MVC ?

Yes we have a Custom View Engine in MVC , by implementing the IViewEngine interface or by inheriting from the VirtualPathProviderViewEngine abstract class.

What is the significance of NonActionAttribute in MVC

In general, all public methods of a controller class are treated as action methods. If you want prevent this default behaviour, just decorate the public method with NonActionAttribute.

What is the use of web API ? Why Web API needed, If you have already RESTful services using WCF ?

we can still develop the RESTful services with WCF, but there are two main reasons that prompt users to use Web API instead of RESTful services. ◾ASP.NET Web API is included in ASP.NET MVC which obviously increases TDD (Test Data Driven) approach in the development of RESTful services. ◾For developing RESTful services in WCF you still needs lot of config settings, URI templates, contract’s & endpoints which developing RESTful services using web API is simple.

What is Web API ‘s in Asp.Net MVC 4 ?

◾Web API is a new framework for consuming & building HTTP Services. ◾Web API supports wide range of clients including different browsers and mobile devices. ◾It is very good platform for developing RESTful services since it talk’s about HTTP.

What is Attribute Routing in MVC?

ASP.NET Web API supports this type routing. This is introduced in MVC5. In this type of routing, attributes are being used to define the routes. This type of routing gives more control over classic URI Routing. Attribute Routing can be defined at controller level or at Action level like – [Route(“{action = TestCategoryList}”)] - Controller Level [Route(“customers/{TestCategoryId:int:min(10)}”)] - Action Level Just add the method – “MapMvcAttributeRoutes()” to enable attribute routing as shown below public static void RegistearRoutes(RouteCollection routes) { routes.IgnoareRoute("{resource}.axd/{*pathInfo}"); //enabling attribute routing routes.MapMvcAttributeRoutes(); //convention-based routing routes.MapRoute ( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Customer", action = "GetCustomerList", id = UrlParameter.Optional } ); }

What are the advantages of MVC over ASP.NET?

Following are 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.

What are the namespace classes used in ASP.NET MVC?

-All the namespaces and classes used for ASP.NET MVC reside in the System.Web.Mvc assembly. -System.Web.Mvc namespace This namespace provides classes and interfaces that support the MVC pattern for ASP.NET Web applications. This namespace also contains classes that manage controllers, controller factories, partial views, action results, views and model binders. -System.Web.Mvc.Ajax namespace This namespace provides classes that support Ajax scripts in an ASP.NET MVC application. The namespace also provides support of Ajax scripts and Ajax option settings. -System.Web.Mvc.Async namespace This namespace provides classes and interfaces that support asynchronous actions in an ASP.NET MVC application. -System.Web.Mvc.Html namespace This namespace provides classes that help in rendering HTML controls in an MVC application. The namespace contains classes providing forms, input controls, links, partial views, and validation support

What is Repository Pattern in ASP.NET MVC?

-Repository pattern is used as a default entity operation that allow the decoupling of the components used for presentation. -Repository pattern allows easy testing in the form of unit testing and mocking. -Repository pattern will have the proper infrastructure services to be used in the web applications. -It uses the mechanism of encapsulating that provides storage, retrieval and query for the implementation of the repository. -Repository patterns are hard coded in the application that is to be used in ASP.NET MVC architecture -Repository pattern is useful for decoupling entity operations form presentation, which allows easy mocking and unit testing. -The Repository will delegate to the appropriate infrastructure services to get the job done. Encapsulating in the mechanisms of storage, retrieval and query is the most basic feature of a Repository implementation. -Repository pattern is useful for decoupling entity operations form presentation, which allows easy mocking and unit testing...

What is Bootstrap in MVC5?

Bootstrap (a front-end framework) is an open source collection of tools that contains HTML and CSS-based design templates along with Javascript to create a responsive design for web applications. Bootstrap provides a base collection including layouts, base CSS, JavaScript widgets, customizable components and plugins. Project Template in ASP.NET MVC5 is now using bootstrap that enhances look and feel with easy customization. Bootstrap version 3 is added to ASP.NET MVC5 template

What is a ViewModel in ASP.NET MVC?

A ViewModel basically acts as a single model object for multiple domain models, facilitating to have only one optimized object for View to render. Below diagram clearly express the idea of ViewModel in ASP.NET MVC: There are multiple scenarios where using ViewModel becomes obvious choice. For example: ◾Parent-Child View Scenario ◾Reports where often aggregated data required ◾Model object having lookup data ◾Dashboards displaying data from multiple sources

What is a ViewEngine in ASP.NET MVC?

“View Engine in ASP.NET MVC is used to translate our views to HTML and then render to browser.” There are few View Engines available for ASP.NET MVC but commonly used View Engines are Razor, Web Forms/ASPX, NHaml and Spark etc. Most of the developers are familiar with Web Forms View Engine (ASPX) and Razor View Engine. ◾Web Form View Engine was with ASP.NET MVC since beginning. ◾Razor View Engine was introduced later in MVC3. ◾NHaml is an open source view engine since 2007. ◾Spark is also an open source since 2008.

What is a ViewEngine in ASP.NET MVC?

“View Engine in ASP.NET MVC is used to translate our views to HTML and then render to browser.” There are few View Engines available for ASP.NET MVC but commonly used View Engines are Razor, Web Forms/ASPX, NHaml and Spark etc. Most of the developers are familiar with Web Forms View Engine (ASPX) and Razor View Engine. ◾Web Form View Engine was with ASP.NET MVC since beginning. ◾Razor View Engine was introduced later in MVC3. ◾NHaml is an open source view engine since 2007. ◾Spark is also an open source since 2008.

request flow in ASP.NET MVC framework

Request flow for ASP.NET MVC framework is as follows:  Request hits the controller coming from client. Controller plays its role and decides which model to use in order to serve the request. Further passing that model to view which then transforms the model and generate an appropriate response that is rendered to client.

Core features of ASP.NET MVC

Core features of ASP.NET MVC framework are: ◾Clear separation of application concerns (Presentation and Business Logic). It reduces complexity that makes it ideal for large scale applications where multiple teams are working. ◾It’s an extensible as well as pluggable framework. We can plug components and further customize them easily. ◾It provides extensive support for URL Routing that helps to make friendly URLs (means friendly for human as well as Search Engines). ◾It supports for Test Driven Development (TDD) approach. In ASP.NET WebForms, testing support is dependent on Web Server but ASP.NET MVC makes it independent of Web Server, database or any other classes. ◾Support for existing ASP.NET features like membership and roles, authentication and authorization, provider model and caching etc.

Difference between ASP.NET MVC and ASP.NET WebForms?

ASP.NET Web Forms uses Page controller pattern approach for rendering layout, whereas ASP.NET MVC uses Front controller approach. In case of Page controller approach, every page has its own controller i.e. code-behind file that processes the request. On the other hand, in ASP.NET MVC, a common controller for all pages processes the requests.

Explain MVC (Model-View-Controller) in general?

MVC (Model-View-Controller) is an architectural software pattern that basically decouples various components of a web application. By using MVC pattern, we can develop applications that are more flexible to changes without affecting the other components of our application. ◾ “Model”, is basically domain data. ◾ “View”, is user interface to render domain data. ◾ “Controller”, translates user actions into appropriate operations performed on model.