All posts by Thiyagu

Jquery Selectors

What is Selector??

As a name implies, selectors allow us to select the elements/properties like div, span., to performing actions on it.

What is use of it ??

A Selector identifies an HTML tag/element by using selector to manipulate(like apply css, delete the div…) with jQuery code.

Types of Selector :

  • ID/Tag ID Selector:

Represents a tag available with the given ID in the DOM. In simple, select the matched elements which has the same id.

Example : $(“#userid”)

<div id=”userid”></div>

  • Class/Tag Class Selector:

It represents a tag available with the given class in the DOM. In simple, select the matched elements which has the same class.

Example : $(“.userid”)

<div class=”userid”></div>

  • Tag Name/Element Selector :

It represents a tag name available in the DOM, In simple, select eh matched DOM/element
which has the same type

Example : $(“p”)

<p id=”userid”></p>

 

New Feature in MVC 5 – Bootstrap

From VS2013, Bootstrap is a sleek, intuitive, and powerful front-end framework for faster and easier web development, created and maintained by Mark Otto and Jacob Thornton.

  • In MVC5 project, Bootstrap is available by default in new MVC5 projects. we can also include in MVC4 by using Nuget.
  • Is it support for all ie Browser’s: It is not recommended for IE7 and below

Why we are using? What is the advantage ?

Now-a-Days, Bootstrap has become an increasingly popular front-end development framework for designing
rich and responsive web pages.The Bootstrap framework provides several benefits for developing rich pages.

Speed of Development

The main/biggest advantages of using Bootstrap it will reduce the developing time of UI.
For example, if you going to start new application with less time, we can use varity of boostrap is available in
the market. It will give more responsive and rich developed code.So making small changes we can achive our goal

Responsiveness

The responsiveness, as a name implies it will have more flexible in all devices like desktop,mobile,tablets…
Boostrap is mainly desined based on the responsive classes.

BootStrap in ASP.NET MVC 5

ASP.NET MVC 5 uses Bootstrap 3 as the CSS Framework in its default ASP.NET Web Application Tempate.
This very nice feature in ASP.NET MVC for developers to make their site more responsive.we can utlize the pleasure of the responsive navigation and website along with all the typography from Bootstrap 3.

Here start with an simple example

STEP 1 :

Create new project using mvc5, bootstrap will also included as default as shown in below (don’t forgot to choose creating mvc application using default template for viewing output)

dotnet-helpers-Bootstrap

STEP 2:

After creating application, run the application to view in the 100% mode as shown below. From the below image, we can see all the menu’s are lined at the top and content also  placed in row manner.

STEP 3:

The main purpose of using bootstrap is to make our website responsive and to make our work much easier.So above pages can adapted to view in any device like mobile,tablet… as shown in below image

In above image, the content are aligned onc by one to adapt the device. And the menu’s are aligned in top most right icon as show in below

New Feature in MVC 5 – ASP.NET Identity

 

In previous article we discussed little bit about Identity. Here we will discuss more information on ASP.NET Identity.

What is ASP.NET Identity?

In Application user can able to login using a user-name and password which are stored in the database/application.Now-a-days,users are closely coupled with social sites like Facebook, Twitter etc.So considering these social integrations, our web based applications need to allow users to
Continue reading New Feature in MVC 5 – ASP.NET Identity

What’s New Feature in MVC 5?

Let’s we have a look into some of the new features which have been introduced in ASP.NET MVC 5. Some of the functionality provides the new features in previous version of MVC, but now some of the features have been improved and released in MVC 5.

Some of the new features are

  • Scaffolding
  • ASP.NET Identity
  • One ASP.NET
  • Bootstrap
  • Attribute Routing
  • Filter Overrides

ASP.NET Identity :

It can be used by any ASP.NET framework such as ASP.NET MVC and Web Forms. Using the Identity functionality, we can easily include the third party authentication in to our application/website like Facebook,google,linked in…

In Application user can able to login using a user-name and password which are stored in the database/application.
Now-a-days,users are closely coupled with social sites like Facebook, Twitter etc. So considering these social integration, our web based applications need to allow users to login into website using third party login credentials. There are numerous sites that support open-ID protocol such as google.

Filter overrides

Using filter overrides, we can apply filters to the action method or controller which particularly excludes the global filter or the controller filter for the particular action method or controller.

If we want to override any of the global action filter in our action , then we just need to apply
the OverrideActionFilters attribute like below.

[Authorize(Users=”Anitha”)][RoutePrefix(“Items”)]
public class ItemsController : Controller
{

[OverrideAuthorization]
public ActionResult GetItems(string itemId)
{
….
}
}

One ASP.NET

One ASP.NET is a new unified project system for .NET Web Developers. It makes developer to work with multiple frameworks like MVC, Web API, Web Forms etc., in a single Application/project.

In simple, using the feature of One ASP.NET we can use ASP.NET Web Forms and MVC together in the same Web application.

Attribute Routing

By using attribute routing we can define the route in the same place where controller/action is defined. So we can decouple controller and action names from route entirely.

[Route(“Items/plastic/{id?}”)]
public ActionResult GetElectronicItems(int? id) {
…..
}

Bootstrap

In MVC5 project, Bootstrap is available by default in new MVC5 projects. We can also include in MVC4 by using Nuget. Bootstrap is nothing but a collection of css classes with more responsive for all devices. Now-a-Days, Bootstrap has become an increasingly popular front-end development framework for designing rich and responsive web pages. The Bootstrap framework provides several benefits for developing rich pages.

Note : By up-coming posts, we will analyse more details about each  MVC 5 feature topic with sample examples. Keep on Reading

Razor View Engine vs Web Form View Engine

What is View Engine in ASP.NET MVC and How It is used?

  • In Asp.net MVC, View engine holds the responsibility of rendering the view to the browser. MVC supports Razor Engine and Web Form by default
  • There are a lot of Third Party View engines available for use, We can go for them as well. Eg: Nhaml, Park, NDjango, SharpDOM etc.,

Lets see the difference between Razor and Web Form View engines.

Razor View Engine vs Web Form View Engine:

Release :

  • Razor Engine was introduced in MVC3
  • Web Form view engine is available since the MVC was introduced with its default View engine

File Extension :

  • Razor Engine has file extensions: 
    • .cshtml for C#
    • .cbhtml for VB, Partial Views, Editor Template and Layout Page.
  • Web Form Engine is set as default View engine in Visual Studio. It has file extensions:
    • .aspx for views
    • .ascx for partial view
    • .master for layouts

Base Class :

  • Namespace for Razor view engine is System.Web.Razor.
  • Namespace for Web Form view engine is System.Web.WebFormViewEngine.

Syntax :

  • In Razor View, we use the @ symbol succeeded by tag. It is not mandatory to explicitly close the code-block
    Eg : @Html.ActionLink(“Click”,”dotnet-Helpers.com”)
  • In Web Form view engine, we use <%: … %>
    Eg : <% :Html.ActionLink(“Click”,”dotnetHelpers”)%>

Comments :

  • Razor uses @* …. *@ for comments.
  • Web Form uses <!–…–> for comments.

Test Driven Development :

  • The Razor Engine supports TDD.
  • Web Form view engine does not support TDD because it depends on the System.Web.UI.Page class

Design Mode :

  • In Razor Engine, it does not support design mode in visual studio.(ie., Preview mode).
  • In Web Form Engine, it support design mode.

Creating Multiple Web.Config files

Where to use?

If we deal with multiple development environments, then it became very tricky to track the environment specific settings. To achieve this VS allows us to have more than one web.Config file in single project

Creating multiple Web.Config files

Step : 1

In Visual Studio, navigate to the Solution Configuration drop down list and choose “Configuration Manager”

Step : 2

The wizard look like below

Then choose the solution configuration drop down and select “New”.

Step : 3

In the wizard enter the name and click “OK”. If your want to copy setting from any other transform then choose it(other settings like Debug,release)

Step : 4

Finally, right-click on Web.Config file and choose “Add Config Transform” to add newly created configuration file under web.config like below

Then click web.config file and see the newly added file(ie., Web.QAMode.config)

Step : 5

Select required mode and run the application.

WCF Service Application vs WCF Service library

 

What is WCF ?

From msdn,

Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application.

Most of the users confuse where to use WCF Service Application and WCF Service library, so here let we find the result for this confusion

where to use Service Application ?

  • If you want WCF services to be host in different platforms,like IIS, Windows service,console application.
    you should choose WCF Library and you can just reference your library from your new host.
  • A service application includes a website host already setup for you.

Where to use WCF Service library ?

  • If you want your Services host to be host in IIS/ASP.NET only, then  we can use WCF Application.
  • A service library is a library of services that a host can reference and startup.

Creating WCF Service Application

Let we create WCF Service Application by using New –> Project –> Choose WCF Service Application

In the Service Library we having IService1 for the service implementation and Service1 as an App.config file for the configuration (instead of web.config as in the Service Application).

In WCF Service Application, we have the following

  • service contract (IService1.cs),
  • service implementation (Service1.svc.cs), and
  • web configuration file (web.config).

then we  have a service host file (Service1.svc).  This  service host file would not be available in WCF Service Library.

 

Creating  WCF Service library

Let we create WCF Service library by using New –> Project –> Choose WCF Service Library

In WCF Service library ,we have the following

  • service contract (IService1.cs),
  • service implementation (Service1.cs), and
  • App configuration file ( instead of web.config )

From the below image we can see  the service host file is not be present in it, so if needed we want to create it manually

How to consume WCF service in MVC

Here we going to discuss about how to  consuming the WCF service in MVC. For creating WCF refer here

Step 1:

Create a new project and add Service References by right click the project as show below

and in Add Service Reference wizard, enter the address of the service and click ok button to check the availability of the service method. we can also change the namespace to consumed service. Finally click ok to add the service reference to our application

Step 2:

Check whether service added correctly as like below screen by double click the service name to open the object browser window (check with web config file for reference)

If service name space is not added correctly in the above screen then right click the the service and choose ‘Configure Service Reference’, in that wizard unchecked the ‘Reuse types in referenced assemblies’ options and click OK ( it will update in webconfig also )

Step 3:

Create Controller to implement the service.

public ActionResult Index()
{
ServiceReference1.Service1Client uDetail = new ServiceReference1.Service1Client();
string uName = uDetail.DisplayUserName("Aadharsh GK");
return Content(uName);
}

Here i am creating instance for the service and passing the parameter to get result string.

Step 4:

Run the application

Output

Creating simple WCF Service

What is Windows Communication Foundation

From msdn,Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application.

An endpoint can be a client of a service that requests data from a service endpoint.

Creating Service

Here i am creating WCF service out side of the application(ie., To  be host in IIS, to use  service by other end)

Step 1:

Open File -> New -> Project (choose WCF Workflow Service Application) like shown below image

Step 2:

After successful creation of project, project hierarchy will shown like below

Step 3:

Let we write the operationcontract in the IService1.cs to consume in the other end point

[OperationContract]
string DisplayUserName(string name);

and then define this contract in the Service1.svc.cs

public string DisplayUserName(string cusName)
{
return “Welcome” + cusName +”to our site!!!”;
}

Output :

After code level completion, check whether its running correctly or not by open the Service1.svc.cs and the press F5 like below, then it will list out the service methods.

Lazy Loading vs Eager Loading

 

What is  Lazy Loding?

As name implies, if we need to load parent data , it will load parent data without loading the related child  data.This is know as lazy loading

Otherwise, data is loaded only on demand (if required)

When to use ?

If we do not want to load the related entity at the same time as when the main entity is loaded/fetched, in this scenario we can use Lazy Loading.

Example :

Here we will see an example for lazy loading with the entity. Let we discuss with two tables, Here we having one table named as  customers which contain customerid,cusotmerName,CusomerMobileNo,customerdetailId ( it refer the primary key of Customerdetails table). then table Customerdetails which contain customerdetailId,customerAddress,Customercity….

var customerList = context.customers.Take(100);

foreach (var Customer in customerList)
{
// Login here
foreach (var CustomerDetail in customerList.Customerdetails)
{
// Login here
}
}

First line of code shows its is working as lazy, because it load only customers table without customerdetails table ( ie., without relations data).

Note :

From the above code, SQL hit will be high ( it will take 100 hits for fetching the customerdetails). Because every time the related data fetch will be happen inside the loop.


What is Eager Loading?

It Load all the related data with the loading object.

When to use ?

If we  want to load the related entity at the same time as when the main entity is loaded/fetched, in this scenario we can use Eager Loading.

Let we see the example for Eager Loading with the entity

var customerList = context.customers.Include(“Customerdetails”).Take(100);

foreach (var Customer in customerList)
{
// Login here
foreach (var CustomerDetail in customerList.Customerdetails)
{
// Login here
}
}

First line show it will fetch all the related entity for the customers table

Note :

Here SQL hit will be only one time , because it will fetch related entity using include keyword (first itself).