Areas in ASP.NET MVC

Areas are some of the most important components of ASP.NET MVC projects. The main use of Areas are to physically partition web project in separate units.  If you look into an ASP.NET MVC project, logical components like Model, Controller, and the View are kept physically in different folders, and ASP.NET MVC uses naming conventions to create the relationship between these components. Problems start when you have a relatively big application to implement. For instance, if you are implementing an E-Commerce application with multiple business units, such as Checkout, Billing, and Search etc. Each of these units have their own logical components views, controllers, and models. In this scenario, you can use ASP.NET MVC Areas to physically partition the business components in the same project.

In short, an area can be defined as: Smaller functional units in an ASP.NET MVC project with its own set of controllers, views, and models.

image

Read full article on the Infragistics blog

How to create Custom Filters in AngularJS

Have you ever used filters with the ng-repeat directive as shown in the listing below?

image

If so, then you’ve used a filter in an AngularJS application. AngularJS provides us many in-built directives like search. If required, AngularJS also allows us to create custom filters, which we’ll explore in this post.

AngularJS gives us a simple API to create a custom filter. You’ll remember that we use app.controller() to create controllers and app.module() to create modules. In exactly the same way, AngularJS has given us the angular.filter API to create a custom filter in AngularJS.

A custom filter can be created using the following syntax:

image

Read full article on the Infragistics blog

What are ViewData, ViewBag, and TempData in ASP.NET MVC?

I have often seen entry level developers struggle with the differences between and usage of ViewData, ViewBag and TempData in ASP.NET MVC. And while there are many articles and blog posts on this topic out there, I’ll try to explain it simply.

To start with, ViewData, ViewBag, and TempData all three are objects in ASP.NET MVC that are used to carry or pass data in different scenario. You may have a requirement to pass data in the following cases:

  • Pass data from controller to view;
  • Pass data from one controller to another controller;
  • Pass data from one action to another action;
  • Pass data between subsequent HTTP requests

At a higher level, we can depict the use of ViewData, ViewBag, and TempData as shown in the image below:

image

Passing Data from Controller to View

Let us consider a scenario where you’re passing data from controller to view. Usually we pass complex data to the view using the model. Here let’s say we have a strongly typed View which is using the data model List as shown in the listing below:

Read the full article on the Infragistics blog

How to create relationships between entities in the Entity Framework Code First Approach

The Entity Framework Code First approach allows us to create a model as a plain class and then the database gets created from the domain model or entity class. In the Code First approach, the database gets created from the classes.

Some advantages of the Entity Framework Code First approach include (as stated in Scott Gu’s blog):

  • Developing without ever having to open a designer or define an XML mapping file
  • Defining your model objects by simply writing “plain old classes” with no base classes required
  • Using a “convention over configuration” approach that enables database persistence without explicitly configuring anything
  • Optionally overriding the convention-based persistence and using a fluent code API to fully customize the persistence mapping

Rather the delving more into theoretical concepts, in this post we will directly jump into code and create a table and database using the Code First approach. In this post we will learn how we can create entities and a relationship between entities in the Entity Framework Code First approach. In the EF Code First approach, there are two options to create the relationship between entities, through:-Data annotations and  Fluent API

In this post we will use data annotations to create the relationship between entities.

Create database with one table

Let us start with creating a table named Student in a database with the code first approach. The domain class Student can be created as shown in the listing below:

image

As you might have already noticed, the Student class is a plain class. Entity Framework will use the Student class to create the table in the database. The Student class represents the domain entity and it should not have any information or references of the database. Entity Framework will use the Student class to create the Student table.

Once the domain entity class is created, next we need to create a Context class which will inherit the DataContext class. The context class can be created as shown in the listing below:

image

Read the full article on the Infragistics blog

Getting started with TypeScript

TypeScript is superset of JavaScript created by Microsoft. TypeScript – according to its website – “lets you write JavaScript the way you really want to. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript”.

Some features of TypeScript include:

  • Support standard JavaScript
  • Static typing
  • Encapsulation using the classes and the modules
  • Constructors, properties and functions supports
  • You can define interface
  • Lambda support Lambda support
  • Syntax checking
  • Type annotations
  • Static or dynamic loading of module contents

TypeScript can be summarized in the following points:

  • TypeScript is syntactic sugar for JavaScript
  • TypeScript syntax are the superset of ECMASCRIPT 5 syntax.
  • TypeScript compiler converts or compiles the TypeScript file into a JavaScript file locally.
  • TypeScript does not reorder the variable declaration
  • TypeScript syntax includes various proposed features of ECMASCRIPT 6
  • TypeScript complies with module codes generation which can by loaded statically or dynamically.
  • TypeScript works with type inference

This post will help you to get started with TypeScript, setting up the environment for TypeScript development in the Visual Studio and Sublime Text. At the end of the post we will create a simple TypeScript program in Visual Studio.

Read the full article on the Infragistics blog