Author Archives: IMRAN ABDUL GHANI

About IMRAN ABDUL GHANI

Imran Abdul Ghani is working as Software Developer(Senior) with extensive knowledge in Web development technologies especially C#, ASP.NET, MVC, WCF, Web API, ADO.NET Entity Framework, jQuery etc. He has several years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET (MCSD.NET) since 2005. You can reach his blogging at www.webdevelopmenthelp.net, www.topwcftutorials.net, and www.sharepointfordummies.net.

Top 20 Entity Framework Interview Questions – MUST HAVE

This post is about Entity Framework Interview Questions that will explore various features, concepts and FAQs regarding Microsoft Entity Framework. It’s basically a collection of most frequently asked Entity Framework Interview Questions for developers. You can also explore some practical solutions implementing Entity Framework here:

You are working with WebDevTutorial and building an ADO.NET Entity Framework application for a client. You need to validate the conceptual schema definition language (CSDL), store schema definition language (SSDL), and mapping specification language (MSL) files. Which Entity Data Model tool can you use? (Each correct answer presents a complete solution. Choose all that apply.)

  • A. EDM Generator (EdmGen.exe)
  • B. ADO.NET Entity Data Model Designer
  • C. Update Model Wizard
  • D. Entity Data Model Wizard
  • E. All of Above
  • F. None of Above

For a complete online test and Practice Exams on Web Technologies, Click Here.

 Correct Answer: B, D

Entity Framework Interview Questions List

More Entity Framework Interview Questions for beginners and Experienced

What is Entity Framework?

Microsoft Entity Framework (EF) is an Object Relational Mapping framework that provides an abstraction layer (a kind of mapping) between two incompatible systems (i.e. Object oriented programming languages with Relational databases). It enables us to interact with relational data in an object oriented way, meaning we can retrieve and manipulate data as strongly typed objects using LINQ queries.Microsoft Entity Framework

Microsoft introduced Entity Framework with .NET Framework v3.5 Service Pack 1 supporting basic Object Relational Mapping support but later EF4 was introduced as second version aligning with .NET Framework v4.0.
Back to top

What are the advantages of using Entity Framework?

Main advantages of Entity Framework are:

  • Separation of Concerns (SoC).
  • LINQ is used as a common syntax for all object queries.
  • Code Auto-Generation.

Back to top

What is Entity Framework(EF) Core?

Entity Framework 7 rebranded as Entity Framework Core 1.0 is basically an object-relational mapping framework that allows us to communicate with database using .NET objects. It’s a lightweight, open-source and extensible framework for targeting .NET Core applications.Entity Framework Core

Entity Framework Core 1.0 has following additional features:

  • Cross Platform i.e. can work with .net core application built for MacOS or Linux.
  • Designed for disconnected/web services.
  • Entity Framework Core is cloud optimized.
  • EF Core is Device Optimized as being lightweight can work with SQLite.
  • Support for relational and non-relational databases.
  • EF Core also has Fluent API that enables a user to override the OnModeCreating strategy on a user’s context and makes it easy to figure the convention model.
  • Built-In convention that effectively builds an initial model based on the entity classes.
  • The EF Core features data annotations that are added to entity classes or properties to influence the EF model.
  • It also has Snapshot change tracking properties based on recording the initial values of an entity as it is retrieved from the database.
  • Notification change tracking enables a user’s entities to signal the change tracker in case property values are modified.
  • Connection resiliency that automatically retries any failed database commands. Connection resiliency comes in handy for connection to SQL Azure which is prone to transient failures.

There are many key features those were available in EF 6.x but not included in Entity Framework Core 1.0.

  • No Lazy Loading.
  • Group By Translation – If query includes a group by clause, it will be omitted.
  • Not Supporting stored procedures.
  • No Graphical Modeling Tools supported.
  • Spatial Data Types (a wrapper around a COM library).
  • Simple Command Interception.

Back to top

What is the Nuget Package console command to install Entity Framework, if it’s not there in you project at that time?

Following is the Nuget Package console command to install Entity Framework:

Install-Package EntityFramework -Version 6.1.1Install Entity Framework -Version 6.1.1
Back to top

How to Install Entity Framework via NuGet Package in Visual Studio?

It’s quite simple to install Entity Framework via Nuget for our project in Visual Studio. For example, If I have just created a new project and want to install Entity Framework, below step by step approach will be helpful.

  1. Right click on the project and choose “Manage NuGet Packages…”.Manage NuGet Packages
  2. On Installation page, choose “Browse” Tab from top left and then enter “Entity Framework” in search box below that and click on search icon. It will list down all Entity Framework related results below. Installing Entity FrameworkAs you can see, we have selected Entity Framework and all details (including version, author, License, Date Published etc.) of the selected item are displayed in right area.
  3. In above screenshot, click on Install button. It will ask for a Review Changes going to be done, confirm by clicking “YES”.Review Install EF
  4. It followed by a License Acceptance confirmation. Just confirm by clicking “I Accept”.License Acceptance EF
  5. Once you accept the License, it will complete the installation displaying details in Visual Studio Output Window as shown in below screenshot.Entity Framework Installed Finally, you can see the successful installation message in Output Window. Once the installation is done successfully, you can see EntityFramework and EntityFramework.SqlServer in References of our project.

Back to top

Where do we use Virtual classes in Entity Framework DbContext Models?

We use Virtual classes in Entity Framework in context class where we define DBSet of corresponding table. As we can see easily in below code sample for Students and Departments:
Entity Framework Interview Questions Virtual Classes
Back to top

Entity Framework uses DbContext, How is it different from Object Context?

DbContext can be used for code first while Object Context doesn’t. It exposes the most commonly used features of ObjectContext.
Back to top

What’s new in Entity Framework 6?

  • Customizing Code First Conventions.
  • Logging of database commands.
  • Stored Procedure Mapping.
  • Asynchronous Queries and Save support.

Whats New In EF6

With EF6, in applications with lots of tables and relationships defined, our context objects open faster. We should also be better insulated from dropped connections (at least, if the drop is transient and not permanent — nothing is going to help there).  EF6 also generates SQL faster from LINQ queries than before (though it’s the same SQL that’s being generated as in earlier versions of EF, so your actual data access won’t be any faster or slower).
Back to top

Can we access a model in Entity Framework without primary key defined?

No, but we can access data.

Using Primary Key:

Student student = db.Students.Find(id);

Without Primary Key:

Student student = db.Students.Where(x=>x.StudentName==”Ahmad”);

Back to top

Why do we use Lazy Loading in Entity Framework?

Entity Framework facilitates us to avoid huge, deep, highly-relational queries, so that the data will not heavy on the web.

Note: As by default, lazy loading option is enabled in Entity Framework but that can cause major performance issues in some scenarios as below:

As for above scenario, student.Department will load department from SQL Server by firing a new SQL query for each iteration and it’s a performance degradation in case of large number of records.
We can disable Lazy loading (or in other words, enable eager loading) by using the following code:

Back to top

Why DB Context models object disposal is important in Entity Framework?

Until it’s disposed, it will be holding resources that aren’t in. If not disposed then Garbage collector will free the space but in some instance it holds up.

Calling dispose method to clear memory.Dispose in Entity Framework
Back to top

Can we do an insertion and deletion at the same block of code and then Apply save changes to them in a statement in Entity Framework?

Yes, WE CAN by using the below piece of code:

Save changes in Entity Framework

Here the student record will insert to db but not physically. When we call SaveChanges method then it actually insert in db and commit the transaction. If we delete before committing transaction nothing will change in database.
Back to top

What are the development approaches are supported in Entity Framework?

Following are the development approaches available in Entity Framework. Implementation of each approach is given in detail in separate Entity Framework Tutorial:

  • Code First Approach – where code defines the database. Entity Framework handles creation. A complete detailed implementation of Entity Framework Code First Approach here.
  • Database First Approach – regular approach used where database is first created or already exists.
  • Model First Approach – where model is drawn first that further generate database scripts.

Development Approaches in Entity Framework
Back to top

If we have not followed proper conventions in Code First approach, then how we can mark a field/property as primary key?

An important point to remember about EF Code First approach; we have to follow proper convention for a primary key, means Entity Framework expects ID combined with Entity Name. In our case, above referred Code First Example, we have two entities (i.e. Category and Product) and for both of these entities, we used proper convention for primary key i.e. CategoryId and ProductId.

But in case we used something different i.e. “UniqueCategoryIdentifier” or “UniqueProductIdentifier”, then we have to tell that this is our primary key column and this can be done using a simple attribute i.e. “Key” as follows:

If we don’t follow the convention as well as not using the “Key” attribute, then will end up with following error.

Note: It’s always recommended to use proper convention or use “Key” attribute to tell Entity Framework about our primary key field.

Back to top

How we can enforce number of characters (minimum or maximum) for a field using Entity Framework Property Annotation method?

We can easily use property annotation of MinLength and MaxLength to enforce minimum or maximum number of characters for a specific field respectively. For example, If we want to have minimum and maximum number of limit for CategoryName field for Category Entity (say minimum 10 and maximum 100 characters). Below is the way to use, MinLength and MaxLength:

Back to top

How we can use a property for an Entity that is not mapped to database in Code First Approach?

In Code First Approach, all properties are normally mapped to database. But in certain scenarios, if we don’t want a specific property to be mapped to database, Entity Framework provides us with NotMapped attribute for annotation.

Let’s take a practical example, we have an entity i.e. Product and we want to have a ProductCode that will not be mapped to database. So, we will do the following to achieve in Code First Approach.

Back to top

What is the query syntax we use to query an ADO.NET Entity Data Model?

We can use LINQ to Query ADO.Net Entity Framework. For Example:

Entity Data Model
Back to top

Is LINQ a feature of Entity Framework?

Yes, following is the example to get student record from Section A.

LINQ feature in EF6

The same in Entity Framework:

Student student = db.Students.Where(x=>x.Section==”A”);
Back to top

Does Default New Project Creation under Internet Template Category of ASP.NET MVC have any DB Context Ready while creating the project?

Yes, There is, as we can see in the below screenshot:Template Category For MVC
Back to top

If you provide the Primary Key value while inserting record to Entity Framework, will that execute fine, or will it throw an error while the adding statement?

Yes it will threw error if same a record present with same data. If identity is set then it will give error in any case.Insert In EF6
Back to top

What are the properties or Database Elements get copied in Dataset when Clone method is used?

It will create a new object with same properties with a new instance.Clone Method in EF6
Back to top

What is the role of a Self-Tracking Entities?

Self-tracking entity allows you to add code generated item:Self Tracking Entities in EF6
Back to top

Can you describe the feature of split entity in Entity Framework?

Entity splitting gives us the ability to take an entity in our model and split this entity into multiple database tables. When we query an entity, Entity Framework will create a query that Automatically joins the related physical tables for us.
Back to top

What is the role of Entity Container in Entity Framework?

Entity container is a logical grouping of entity sets, association sets, and function imports.  The following must be true of an entity container defined in a conceptual model:

At least one entity container must be defined in each conceptual model.  The entity container must have a unique name within each conceptual model.

Entity Container in EF
Back to top

Do we need to define any assembly references of entity framework if we use in web.config file?

Yes, that is necessary:web.config for Entity Framework

Back to top

More Entity Framework Interview Questions including Entity Framework Core

LINQ to SQL Vs Entity Framework?

Following table clearly explains the difference between LINQ to SQL Vs Entity Framework:

Entity Framework LINQ to SQL
Work with any database including SQL Server, Oracle, MySQL, DB2 etc. Works but limited to SQL Server.
Entity Framework works well in enterprise scenarios where requirement is to develop a loosely coupled application. LINQ to SQL is good in rapid application development scenarios but follows a tightly coupled approach.
Entity Framework maintain a conceptual model that actually maps to storage model using a mapping. So, it’s possible that multiple EF classes map to one table or multiple tables map to one EF class. A LINQ Entity directly maps to one SQL Server table only. In order to maintain a relationship, it generates a .dbml file.
Can generate database from model and it’s a key feature. Generate database from model is not possible.
Back to top

How to handle transactions in Entity Framework 6

Transaction being a single unit of work that are either successful or failed has really important for an application that is developed using Entity Framework. Entity Framework supports transactions in following ways and this Entity Framework 6 Interview Questions demonstrate the same:

The “SaveChanges()” method in Entity Framework operates within a transaction and saves results of the work. This is how the data integrity is being ensured.

In Entity Framework 6.0, two new APIs are used to maintain the transaction:

1. DbContext.Database.BeginTransaction: Below we can find source code to understand that how different operations are combined within the same transaction and further are all committed or rollbacked. This method also allows us to specify the isolation level for the transaction.

2. DbContext.Database.UseTransaction: It allows DbContext to use a transaction that was stated outside of the Entity Framework. It means using this API we can use any existing transaction with Entity Framework.

It is used when sometimes we must use an existing transaction that is started outside of the Entity Framework.

Back to top

  • Learn ASP NET MVC 5 step by step [Maruti Makwana, Corporate Trainer] 28 Lectures, 2.5 Hours Video, Intermediate Level
    Very easy to learn video series on Asp.Net MVC 5 Specially for those who are familiar with Asp.Net Web forms.
  • AngularJS for ASP.NET MVC Developers [Brett Romero] 10 Lectures, 1 hour video, Intermediate Level
    The Fastest Way For .NET Developers To Add AngularJS To Their Resume
  • ASP.NET with Entity Framework from Scratch [Manzoor Ahmad, MCPD | MCT] 77 Lectures, 10 hour video, All Level
    Latest approach of web application development
  • Comprehensive ASP.NET MVC [3D BUZZ] 34 lectures, 14 Hours Video, All Levels
    From zero knowledge of ASP.NET to deploying a complete project to production.

Concluding Notes:

Again, this is my prepared list of important Entity Framework Interview Questions but reader can suggest/contribute more related concept area. I’ll be more happy to add those questions/concepts and update the Entity Framework Interview Questions list.

More Related Articles:

Top Web Developer Interview Questions and Answers Series:

ASP.NET MVC Jobs [Updated Daily]

Top ASP.NET MVC Jobs

IT Software Developer
Source: Far Bank Enterprises
Details: Developing applications using Microsoft technologies, including C# and ASP.Net MVC. Far Bank Enterprise is seeking a Software Developer to join our IT team on...  More
15 days ago

Bainbridge Island, WA 04-February-2017

.Net Developer
Source: Ramsoft Systems, Inc.
Details: ASP.Net, MVC Framework, C#, Entity Framework. Hope you are doing well....  More
19 days ago

Richmond, VA 23229 31-January-2017

.NET Developer with Microsoft Active Directory
Source: Ramsoft Systems, Inc.
Details: ASP.Net, MVC Framework, C#, Entity Framework. Hope you are doing well....  More
22 days ago

Richmond, VA 23229 28-January-2017

Software Developer II
Source: Almac Group, Inc
Details: C#, .NET 4.5 or higher, Linq, ASP.NET MVC, Visual Studio 2013 or higher. Almac Group is a group of established businesses at the forefront of the Pharmaceutical...  More
3 days ago

Lansdale, PA 19446 17-February-2017

Junior Level .NET Developer
Source: Levi, Ray & Shoup, Inc.
Details: Time to get to work! LRS Consulting Services is seeking a Junior Level .NET Developer for a 3-6 month contract-to-hire opportunity with our client in Central  More
2 days ago

Illinois 17-February-2017

Software Developer
Source: Indeed
Details: Experience with Microsoft *Visual Studio 2013+* and *C# 4.5.* Experience creating *WCF* and *Web API* services. Understanding of *object oriented design* &   More
24 days ago

Redmond, WA 26-January-2017

Software Developer - Operations
Source: Hudl
Details: You’ll likely be working with technologies like React and Bootstrap, C# and ASP.NET MVC, MongoDB, and a number of AWS services....  More
12 days ago

Lincoln, NE 68508 07-February-2017

Junior .NET Developer
Source: SBG Technology Solutions
Details: Must have a clear understanding of ASP.NET MVC, and MVC application design pattern experience. At least five (5) years of development experience, including 4+...  More
5 days ago

Alexandria, VA 22314 14-February-2017

Software Developer
Source: Indeed
Details: *Michigan based applicants ONLY* Equal Opportunity Employer; E-Verify Participant _\*Please do not apply if you are not legally authorized to work in the  More
4 days ago

Lansing, MI 15-February-2017

Software Developer
Source: Indeed
Details: _Experience with Microsoft .NET C# and ASP.NET, MVC, & Entity Framework_. Intellicheck Mobilisa is a publicly-traded technology company located in Jericho, NY...  More
5 days ago

Jericho, NY 14-February-2017

Junior .NET Developer
Source: Publishers Clearing House
Details: Windows Forms, WCF, ASP.NET, MVC. Publishers Clearing House (PCH), headquartered in Port Washington, NY (soon to be Jericho, NY!)....  More
30+ days ago

Port Washington, NY 11050 12-December-2016

Software Developer
Source: Altruista Health
Details: Deep technology experience, including ASP.Net, MVC, C#.Net, SQL Server 2008, and SQL Server 2012. Altruista Health, Inc., is seeking an experienced professional...  More
12 days ago

Reston, VA 20190 07-February-2017

.Net Developer
Source: Indeed
Details: MVC:. Develop web, web services and back-office applications using the newest Microsoft stack of technologies including Net CORE, ASP.NET, MVC, Angular,...  More
2 days ago

Charlotte, NC 17-February-2017

ASP.NET/Angular Developer
Source: Intellisoft Technologies
Details: No new resumes ASP.NET/Angular Developer BlackHawk 700 State Hwy. 121 Bypass Suite 200 Lewisville, Texas 75067 6+ Month Contract Industry leading Client...  More
30+ days ago

Dallas, TX 05-January-2017

Certified Microsoft .NET Developer
Source: Indeed
Details: The project includes .Net MVC web applications with heavy use of JavaScript, jQuery and Kendo UI components....  More
4 days ago

Madison, WI 15-February-2017

.NET Developer
Source: NYC Careers
Details: Experience building full-featured software with ASP.NET MVC, WebForms, VB.NET, SQL and Javascript. The Kings County District Attorney's Office, located in the...  More
4 days ago

Brooklyn, NY 15-February-2017

.Net Developer
Source: Indeed
Details: ASP.NET MVC, JQuery, Entity framework, HTML programming. .Net MVC 4.0 and Strong experience in designing and developing layered web based applications with...  More
18 days ago

Bellevue, WA 01-February-2017

.NET DEVELOPER
Source: Indeed
Details: ASP.NET MVC, JQuery, Entity framework, HTML programming. .Net MVC 4.0 and Strong experience in designing and developing layered web based applications with...  More
18 days ago

Seattle, WA 01-February-2017

Software Engineer C# .Net Developer
Source: MorphoTrust
Details: Responsible for software design and implementation (C#/.Net, ASP.Net MVC, SQL Server, Javascript), testing, debugging, assurance testing, and creation of...  More
30+ days ago

Bloomington, MN 18-January-2017

Software Development Engineer I
Source: Apptio
Details: You: You are a software engineer who strives for excellence in the user’s experience as well as in your technical solutions. You have a curious mind and a...  More
30+ days ago

Bellevue, WA 05-January-2017

NET DEVELOPER - SENIOR (FULL-TIME CONTRACTUAL)
Source: State of Maryland
Details: ASP.NET MVC with Razor. SQL Server 2012, Visual Studio 2015, .NET 4.6 and MVC 5. Development, maintenance, trouble-shooting and debugging of .NET applications...  More
2 days ago

Baltimore, MD 17-February-2017

Developer - Full Stack ASP.NET MVC, C#, SQL Server
Source: Indeed
Details: ASP.NET MVC, C#, SQL Full Stack Server Developer (Austin, Tx)*. Who We Are ...*....  More
2 days ago

Austin, TX 78759 17-February-2017

Mid .Net Developer
Source: Indeed
Details: *Secret Clearance Required!!!!* Current contract until 2020! This highly responsible position involves using established work procedures to analyze, design,  More
5 days ago

Herndon, VA 20171 14-February-2017

Senior Developer
Source: Indeed
Details: Knowledge or experience in ASP.NET, MVC 3+, WCF, ADO.NET. NO C2C PLEASE*....  More
6 days ago

Chicago, IL 60654 13-February-2017

Software Engineer/Developer
Source: ITR (Information Technology Resources)
Details: Candidates demonstrating applied experience with ASP.NET MVC, Java, and Linux will be given extra consideration....  More
30+ days ago

Oak Ridge, TN 08-January-2017

Top Web and Mobile Development Video Online Courses for $10 Each

January Sale 728x90
You must have set some target to stay ahead in your career for this New Year 2016. In order to improve your technical skills as an IT professional, there are thousands of online courses available online at udemy.com that can be really helpful for you.

Best part is that all these courses are available just at $10 each (Limited Time Offer till 11-Jan-2016)

  • The Complete iOS 9 Developer Course – Build 18 Apps ($10 Only)
  • The Complete Android Development Course – Build 14 Apps ($10 Only)
  • iOS 9 and Swift 2: From Beginner to Paid Professional ($10 Only)
  • Learn and Understand AngularJS ($10 Only)
  • The Complete Web Developer Course ($10 Only)
  • Learn To Code by Making Games – The Complete Unity Developer ($10 Only)
  • Learn and Understand NodeJS ($10 Only)
  • Bootstrap Basics: Program Responsive Websites ($10 Only)
  • Build Responsive Real World Websites with HTML5 and CSS3 ($10 Only)
  • JavaScript: Understanding the Weird Parts
  • The Complete Java Developer Course
  • C# Programming from Zero to Hero : The Fundamentals
  • The Web Developer Bootcamp
  • and 1,000s of more…
January Sale 640x480

Customizing Profile Info in ASP.NET Identity

This Video Tutorial explains how to extend the ASP.NET Identity Provider?. It’s a video version of my earlier article published here as “How to Customize Profile Info in ASP.NET Identity?“. Thanks to Webucator Team for providing a video version to facilitate my blog readers for better understanding. The article explains step by step approach to customize profile in ASP.NET Identity.

Webucator provides onsite and online training on multiple Technologies including Microsoft ASP.NET. You can follow the link to Webucator’s ASP.NET Online Training here.

  • Learn ASP NET MVC 5 step by step [Maruti Makwana, Corporate Trainer] 28 Lectures, 2.5 Hours Video, Intermediate Level
    Very easy to learn video series on Asp.Net MVC 5 Specially for those who are familiar with Asp.Net Web forms.
  • AngularJS for ASP.NET MVC Developers [Brett Romero] 10 Lectures, 1 hour video, Intermediate Level
    The Fastest Way For .NET Developers To Add AngularJS To Their Resume
  • ASP.NET with Entity Framework from Scratch
    [Manzoor Ahmad, MCPD | MCT] 77 Lectures, 10 hour video, All Level
    Latest approach of web application development
  • Comprehensive ASP.NET MVC [3D BUZZ] 34 lectures, 14 Hours Video, All Levels
    From zero knowledge of ASP.NET to deploying a complete project to production.

Are you looking for a Web Development Jobs in Gulf Region? Please follow below:
Top Gulf Jobs

Creating your first SPA Application using AngularJS and WebAPI – All CRUD Operations

Practical AngularJs Tutorial

SPA is an application which is built in a single page to give user much rich windows application experience and impressively increases performance of the website.

In this ASP.NET Web API Tutorial, we are going to learn How to create a ASP.NET Web API Application and use it in a SPA AngularJS page in the same project? Technologies being used in this web development tutorial are:

  • ASP.NET Web API
  • AngularJS
  • Bootstrap

Followings are the tools and IDE used for this project:

  • Visual Studio 2012 Update 2 or beyond.
  • Localdb in Visual Studio.

Microsoft ASP.NET Web API framework is the best choice for developing HTTP services in more simpler way. It enables us to reach more wider ranger of clients such as browsers as well as mobile devices. In order to understand more about the technology, you can read “Practical Guide to ASP.NET Web API” that is a practical way to learn about Web API.ASP.NET Web API

This AngularJS and Web API Tutorial is not including testing of the project. This article will introduce you to explain how we can use ASP.NET Web API in AngularJS.

If you further interested to enhance your AngularJs Skills, you can follow the Advanced AngularJS Interview Questions list that explains the key concepts and provide extensive source code for developer understanding.

What is Single Page Application(SPA)?

Single Page Application (SPA) is a web application which enhances the User Experience by using HTML5 and AJAX. As the below comparison of SPA and Traditional Page Lifecycle, we can easily understand that SPA avoids one extra postback/reload by sending an AJAX request and receiving JSON as response.SPA Vs Traditional Page Lifecycle

Step by Step Approach to Create a SPA Application using AngularJS and ASP.NET Web API

Now, we will follow a step by step approach for creating a SPA Application performing all CRUD (Create, Retrieve, Update, Delete) operations.

Step 1: Create a new “ASP.NET Web Application” in Visual Studio 2013 or above, name it as “Students” and press OK button as below.SPA Application using AngularJS and Web API

Next dialog box asks for selecting the template. Please select the Project Template to be MVC and uncheck the Windows Azure web publish Option (i.e. Host in the cloud) and press OK.ASP.NET MVC & Web API Application
A new solution for ASP.NET Web Application will be created in Visual Studio.

Step 2: In the App_Start folder create a Local Database named “Students“. So, right-click on App_Start and choose “Add -> New Item”.Local Db SPA ApplicationChoose “Data” from left and select “SQL Server Database” and name it “Students.mdf” as below and press “Add” button.
Single Page Application Database
Step 3: Now we have our Database ready, and it’s time to create students table in the database, let’s create a students table in that Database.
Create Db in Visual Studio 2013
Database Table in Visual Studio 2013So, we have successfully created a “Students” table with fields as Id, StudentName, StudentRollNo, StudentDepartment, StudentbatchNo, StudentYear etc. In order to keep things simple, we have taken most of the fields as text fields except the Id.

Step 4: Now its time to create an “ADO.NET Entity Data Model”. This will create an Entity framework Database Context to work on for accessing the Database.

These are the 5 steps to create an “ADO.NET Entity Data Model”.

  1. Select add new item in Models folder to add an “ADO.NET Entity Data Model”.ADO.NET Entity Data Model
  2. Select “ADO.NET Entity Data Model” and name it as StudentsDB.EDM for SPA Application
  3. Select the option EF Designer From Database (This option lets the configuration knows that we want to use Entity Framework SQL client here).

    Here in this Web API Tutorial, we are using EF Designer From Database option, but if you are interested to learn more about Model-First Approach, please follow other web development tutorial “Understanding Model-First Approach in MVC5 with EF6“.

    EDM Wizard in Visual Studio 2013

  4. Select the database that we created.Connection String in Visual Studio 2013
  5. Now the final step to add the tables in the Database to the Database Context of “ADO.NET Entity Data Model”.Db Objects and Entity Framework

Step 5: Now Build the project and Create a Web API Controller with Scaffolding using the local database “Students” class and the DB Context that we just created:

  1. Add a New Item in the controllers section:ASP.NET MVC Controller
  2. Select “WEB API 2 Controller with actions, using Entity Framework”:Web API 2 Controller using Entity Framework
  3. Select the Student’s Entity and Students Model for Scaffolding process and name the controller as StudentsAPIController.Controller in ASP.NET Web API

Step 6: Confirm that you have WebApiConfig to define API URL Routing as below:WebAPIConfig for  Web API SPA Application

Note: If you are not very much familiar with Routing in ASP.NET MVC and Web API Application, please follow here.

Step 7: Make sure your Web API routing and Bundling are defined in the Global.asax as:Global.ascx Settings in ASP.NET Web API Application
Exam: 70-486
Step 8: Add the AngularJS Nuget Package to our project:AngularJS Nuget Package in Visual Studio 2013

We will notice some new scripts are present in the script folder related to AngularJS.

Step 9: Let’s create a folder in scripts as “MyScripts” and add three more script files for our Students Module, Named as:

  • Module.js
  • Service.js
  • Controller.js

AngularJS Scripts for SPANow I will share the Module, Service and Controller of AngularJS with you.

Let’s start with Module.js. Below is the content of Module.js:

Here we have created the Students Module in Angularjs

Further, I have described the AngularJS Student Service module that I have created for accessing the Web API. Now let me show you the service I created for accessing the ASP.NET Web API of the project:

Below is the content of Service.js:

Now I would like to show you the Angular students controller for the events on the page:
Below is the content of Controller.js

Step 10: Now lets create an empty Student controller for the only page view of our single page application:ASP.NET MVC Controller in Microsoft Visual Studio

Step 11: I have done some textual modification of the Shared Layout view.
The new layout is:AngularJS Modules
This is mainly textual changes and adding the angular script files.

Step 12: Now let’s add the students view within the index action and bind it with bootstrap, I have used bootstrap designing in this. Let me share the HTML of the Students Page:

 

Step 13 : Since it’s a Single Page Application you should probably select Students Controller and Index method as your default page:

RouteConfig for SPA Application

Congratulations!!! Now our website should be ready, Lets try building and running the page and we will see a view like this.Single Page Application using AngularJS

Learn Professional Web Development in AngularJS while building 10 unique Web Apps.
77 lectures, 14.5 Hours Video, All Levels

  • Your First Angular Website
  • Web Template Store
  • myContacts App
  • ngSocial Facebook App
  • Job Directory
  • KnowledgeBase
  • User Authentication App
  • Instagram Gallery
  • PubNub Chat
  • AutoFind

And also we will find Quiz at the end of each application to verify the skill improvement.

Hopefully, this Angularjs tutorial will be helpful for reader in creating his/her First Single Page Application using AngularJS and Web API with all CRUD Operations. Complete source code for the given article will be available soon.

Native Vs Hybrid Mobile Application Development

Native Vs Hybrid Mobile Application Development – it’s a choice you have to make once you get started with mobile app development. Native Apps are conventional and they are called this way, because they use the native language of the platform. An app developed for Android platform can only be utilized by users of Android. Each platform, however, has a separate framework: Apple has Objective C, Microsoft uses C# and Visual Basic, Google deploys Java.

That means that in order to create a native mobile app – you will need to learn and apply three separate ways of coding. It is true that most mobile devices have similar features such as audio, mikes, touchscreens and GPS. Since these are all properties that need to be developed on every respectable mobile device – it doesn’t make sense to have various code bases to accomplish pretty much the same effect.
Native Vs Hybrid Mobile Application Development

Here’s where hybrid cross-platform solutions come to play and they are very successful. You need to master only one technical language and you may cater to every platform, which supports this language. Of course when you pick this framework – you have to definitely check compatibility with the operational system.

Native vs Hybrid Mobile Application Development

Think about it! It is a very popular issue in modern application development – it is sort of a war between experts. Hybrid Apps are usually the cheap and fast solution. Native hybrids are platform sensitive and require deep knowledge. But Native mobile app development can help you harness the platform’s full potential. Native Apps also perform better and are available in app stores. They often cost more but still they dominate the market.

Feature Native Hybrid
Performance Faster Response Compartively slower than native but better than pure HTML5
Accessibility Integration with Camera, Notification, Geolocation, Contacts, Calendar Integration with Camera, Notification, Geolocation, Contacts, Calendar
UI Design Rich UI Design Rich design but not as rich as Native
Storage Online & Offline Online & Offline
Required Dev. Skills Objective C, Java etc. HTML5, CSS, JavaScript
Distribution Downloadable directly from AppStore to device Directly from AppStore to device
When we compare, we have to have in mind that Hybrid Apps and Native Apps have different purposes. A Native App usually offers the best performance, the most profound integration and amazing user experience, although it is often the most complicated way of app development. The Hybrid Approach to well development has recently gained popularity. They are sort of a compromise between a Native App and a web-based app. The key challenge is to combine the unique features of the native and web technologies, so that you might create a really user-friendly and attractive application.Microsoft Certification Exams: 70-480

Among the popular Hybrid Apps are Instagram, and Facebook, and they are everything the users can hope for and dream of. Shazam and Angry Birds are also lovable Hybrid Apps. This means that both approaches to app development can be crowned with success. The answer really is up to you. You should have in mind your most important goals and of course your users.

Research your options and inform yourself well before you start the project. Fellow developers might tell you that you can hardly get a Native experience in a Hybrid App. You have to keep in mind that with Hybrid Apps we can’t do everything, because they have limitations namely with heavy graphic, intensive applications. But if you think about budget, you would want to use a hybrid framework.

So, choose your weapon!

Are you looking for a Web & Mobile Development Jobs in Gulf Region? Please follow below:

jQuery Vs AngularJS – A Good Comparison

In this Web Development Tutorial, I’ll try to answer to very common question related to jQuery and AngularJS i.e. What is the difference between jQuery and AngularJS? or jQuery Vs AngularJS?jQuery Vs AngularJS

Instead of just explaining the difference and listing features of both technologies, I further tried to provide answer for more related questions as well as concepts, For example:

  • When to use jQuery or AngularJS?
  • How to avoid common mistake of using AngularJS in jQuery Fashion?
  • Developer’s perspective – Code Comparison
  • Can we use jQuery inside or with AngularJS?

You can find a comprehensive list of AngularJs FAQs Tutorial explaining multiple related concepts here. If interested to build your professional SPA application using AngularJs and Web API, follow another Angularjs SPA Tutorial here.

What is jQuery?

jQuery is a lightweight and feature-rich JavaScript Library that helps web developers by simplifying the usage of client-side scripting for web applications using JavaScript. It’s extensively simplify using JavaScript on a website and it’s lightweight as well as fast.

So, using jQuery we can:

  • easily manipulate the contents of a webpage
  • apply styles to make UI more attractive
  • easy DOM traversal
  • effects and animation
  • simple to make AJAX calls and
  • utilities and much more… etc.

As mentioned earlier, jQuery is a JavaScript library, so we can use this library in our application partially/fully to fulfill a single or many of the features it provides (as listed above). For example, we can simply use jQuery library in our application to give some effects and animations or simply making AJAX-based calls or using all of the above listed features. It’s just like a plugin.

What is AngularJS?

AngularJS is a product by none other the Search Engine Giant Google and it’s an open source MVC-based framework (considered to be the best and only next generation framework). AngularJS is a great tool for building highly rich client-side web applications.

As being a framework, it dictates us to follow some rules and a structured approach. It’s not just a JavaScript library but a framework that is perfectly designed (framework tools are designed to work together in a truly interconnected way).

In comparison of features jQuery Vs AngularJS, AngularJS simply offers more features:

  • Two-Way data binding
  • REST friendly
  • MVC-based Pattern
  • Deep Linking
  • Template
  • Form Validation
  • Dependency Injection
  • Localization
  • Full Testing Environment
  • Server Communication

Note: In order to get more detailed information about MVC, please follow here.

Learn Professional Web Development in AngularJS while building 10 unique Web Apps.
77 lectures, 14.5 Hours Video, All Levels

  • Your First Angular Website
  • Web Template Store
  • myContacts App
  • ngSocial Facebook App
  • Job Directory
  • KnowledgeBase
  • User Authentication App
  • Instagram Gallery
  • PubNub Chat
  • AutoFind

And also we will find Quiz at the end of each application to verify the skill improvement.

When to use jQuery or AngularJS?

Most of the time people fails to comprehend the real value of these technologies during application development. AngularJS is best suited for the web application development as it works on the HTML code and JSON data which helps in developing for interactive and robust applications but using same for a simple website development results in slow loading and quite erratic websites.

While jQuery is a fast and feature-rich language which has a a commendable JavaScript library and a great tool for creating feature-rich websites. It has in-built features such as HTML document traversal, event handling, manipulation, animation and Ajax support and other which makes it easier and simpler to develop hardcore websites. Therefore before utilizing any of these highly intuitive and robust languages it is necessary to frame a sound approach dedicated either to develop an advanced web application or website development.
Microsoft Certification Exams: 70-480

Don’t use AngularJS in jQuery Fashion

jquery enjoys a huge presence of plugins which makes it easier for the developer to plug these in the websites and let it do the remaining job. On the other hand, AngularJS possesses a completely different structure which makes it harder to find any plugins or to create one which can be simply placed on the website and left for good. AngularJS has jqLite which possess the jQuery functionalities and it can be used for developing different plugins as per the need of websites but stay away for developing or patching codes of old plugins and embedding it on the website.

Code Comparison

For a developer perspective, the code comparison is as follows:
jQuery Vs AngularJS Code

Can we use jQuery inside or with AngularJS?

In certain scenarios, we may want our AngularJS application to use jQuery library. Now, AngularJS can use jQuery in our application when the application is being bootstrapped. Otherwise, Angular will use its own implementation of the subset of jQuery that we discussed above jqLite.

Final Thoughts:

While taking a view AngularJS Vs jQuery, it should be understood that one doesn’t neither-neither replaces other nor does it competes with each other. JQuery is best suited for DOM manipulation while AngularJS is suited for web application development. So when you are looking to develop robust applications, then opt for AngularJS and in order to add more functionality and to perform DOM manipulation on the website then stick with jQuery.

Are you looking for a Web Development Jobs in Gulf Region? Please follow below:
Top Gulf Jobs

Top 5 Most Read Articles of Year 2014

Year 2014 is about to end and it has been most successful year for Web Development Tutorial so far, since I started it in year 2012. Readers remain engaged with WebDevTutorial blog and kept posting their feedback and suggestions through blog comments and Contact Me form. WebDevTutorial not only provided helpful technical articles in year 2014, but also provided following more interesting and free valuable material for developers as:

  • Question of the Day
    A question a day for web developers to involve and enhance their development skills.
  • Free Online Tests
    Online available tests on various web technologies including HTML5, ASP.NET, ASP.NET MVC, AJAX, jQuery). It’s ideal for a web developer to test his/her skill before appearing for an Interview. I’ll add more Free Online Tests in coming year for reader to validate his/her skillset online.
  • Online Certification Practice Exam: 70-486 (Developing ASP.NET MVC Web Applications)
    WebDevTutorial provides a Professional Practice Test of 40 questions and 90 minutes for Microsoft Certification Exam:70-486 allowing developers to validate their skills before appearing for actual certification exam.

Following is a snapshot of user participation at WebDevTutorial displaying top scorer in one of the available Online Tests.Top Scorer in ASP.NET MVC TestLooking into user response on above material, I am determined to:

  • Keep posting daily question on routine basis.
  • More and more Free Online Tests (soon you will see JavaScript and C# tests available here).
  • More Practice Certification Exams online.

With above Online Tests, Exams, blog articles, Source Code and eBooks; WebDevTutorial becomes an ideal platform for web developers to engage and enhance their skills.

Coming back to blog articles, following tutorials are chosen to be the best 5 articles of year 2014 on WebDevTutorial with respect to readership and user feedback:

  1. MVC3 Vs MVC4 Vs MVC5 Vs MVC6
  2. Practical Guide to ASP.NET Web API
  3. HTML5 Interview Questions (a MUST Have)
  4. ViewBag Vs ViewData Vs TempData Vs Session
  5. Reference Material Exam: 70-486 (Developing ASP.NET MVC Web Applications)

1. Difference between MVC3, MVC4, MVC5 and MVC6

MVC3 Vs MVC4 Vs MVC5 Vs MVC6Since the release of first version of ASP.NET MVC in March 2009, Microsoft is trying it’s best to provide improvements as well as new features in every newer version. That’s why ASP.NET MVC has become an ideal framework for developing large scale applications on Microsoft plateform. In this featured ASP.NET MVC tutorial, we discussed in details about new features and improvements in various versions of MVC. For example:

  • ASP.NET MVC3: Razor View Engine and Templates for HTML5/CSS3 were the key features.
  • ASP.NET MVC4, ASP.NET Web API and support for OAuth/OpenID were introduced.
  • ASP.NET MVC5, Attribute Routing, Bootstrap and ASP.NET Identity were key feature.
  • ASP.NET MVC6, vNext is Open Source supporting Cloud Computing.

I have summarized the key features in my personal opinion here but there are many other interesting new features as well as improvements done in different versions. You can follow here for more detailed comparison of each version.

2. Practical Guide to ASP.NET Web API

ASP.NET Web API is an amazing open source framework for building HTTP services supporting more broader range of clients like browsers, mobile devices etc.
ASP.NET Web API

It was introduced in ASP.NET MVC version 4 for building services easily. This Web API tutorial explains:

  • why we weed it?
  • What it does for us?
  • and how it simplifies our work?

It aggregates all required practical implementations starting with a very simple ASP.NET Web API service and building/consuming that service with all CRUD (Create, Retrieve, Update, Delete) operations. Further discussing new features in ASP.NET Web API 2, implementing model validation in Web API service, multiple ways to handle exceptions in steps and finally Top Interview Questions on ASP.NET Web API are given. You can even download the PDF version of this guide here.

3. HTML5 Interview Questions (a Must Have)

It’s Part-1 in Series of MUST HAVE Interview Questions for HTML5. If you are a beginner for latest HTML standard i.e. HTML5 and wanted to grasp this version in a fast track mode or you are going to appear for an web developer Interview, this series of Interview Questions will be very helpful. I focused on most important topics related to HTML5 including:

  • differences with older version
  • Structuring elements
  • Form elements with practical implementation and source code.
  • Graphics (SVG Vs Canvas).
  • Using Canvas to draw simple graphics.
  • Application Cache in HTML5 and how to enable it.
  • HTML5 Web Worker and it’s limitations
  • localStorage in HTML5 and browser support for it.
HTML5 Interview Questions

4. ViewBag Vs ViewData Vs TempData Vs Session

With ASP.NET WebForms, Controller(Code-Behind file that is .cs or .vb) is tightly coupled with View(.aspx file) because it follows Page Controller approach. This is not the case for ASP.NET MVC as it follows front controller approach which decouples all these components. So, in such cases, we have multiple ways to pass data from Controller to View. I have discussed all these approaches in detail with code sample here as:

ViewData Vs ViewBag Vs TempData

5. Reference Material Exam:70-486 (Developing ASP.NET MVC Web Applications)

Microsoft Certification Exam: 70-486 tests a developer’s skills on ASP.NET MVC, HTML5 and CSS3 through real time practical scenarios.
70-486 Developing ASP.NET MVC4 Web Applications

As a reference for Exam:70-486, I have categorized the content in following major parts as:

  • Key requirements for Exam: 70-486
  • Reference Study Material – An extensive lists of reference material including eBooks, Tutorials etc.
  • Online Tests (Available tests on ASP.NET MVC, HTML5 and other web technologies.
  • Complete Online Practice Exam – Appear for a complete Online Practice Exam with 40 questions and limited time.

Hopefully, you have enjoyed web development with me @ Web Development Tutorial and continue this journey with me coming year.

Wish you an advance Happy New Year :)

Exam: 70-486-Developing ASP.NET MVC Web Applications

Microsoft Certification Exam: 70-486 is about testing one’s knowledge for Developing Web Applications using ASP.NET MVC, HTML & CSS. Purpose of this post is to provide reader step by step with:

  • Good reference Material for Exam: 70-486 available online (including Free eBook, Articles etc.)
  • Free Online Tests about ASP.NET MVC (Professional Free Tests)
  • A Complete Online Practice Exam – Must take before appearing for actual exam (because actual exam costs you around $150). This Online Practice Exam: 70-486 provides you with almost same experience as that of real exam.

Exam: 70-486 PDF [Releasing Soon…..]

We are preparing a PDF document that contains list of 70-486 exam questions with correct answer and short description of the correct answer. So, keep in touch and be the first to get the exam 70-486 pdf.

Below are the topics listed by Microsoft itself that are covered in this exam.

  • Design the application architecture
  • Design the user experience
  • Develop the user experience
  • Troubleshoot and debug web applications
  • Design and implement security

For further details about above topics, please follow this link to Microsoft Certification Exam Site  here. Initially this exam was covering questions on ASP.NET MVC4 only but from September 2014 onward, questions from ASP.NET MVC5 and Windows Azure are also included.

Exam: 70-486

You can find changes to Exam: 70-486 related to MVC5, Visual Studio 2013 and Windows Azure tasks in a properly formatted tabular format. This PDF document clearly explains the Tasks Added or changed in every respective topic/area. Click here to download the PDF document.

Reference Material for Exam: 70-486

If you are looking for reference material, the best reference you can have is the “Exam Ref 70-486: Developing ASP.NET MVC 4 Web Applications” by William Penberthy from Microsoft Press.70-486 Developing ASP.NET MVC4 Web ApplicationsYou can get Exam Ref 70-486: Developing ASP.NET MVC4 Web Applications (Free  eBook | Buy Paper book online). But this book covers ASP.NET MVC4 only.

For ASP.NET MVC5, PluralSight  has provided video tutorials on MVC5 Fundamentals including Web Developer Tools for Visual Studio 2013, Identity and Security, Entity Framework 6 and Web API2 etc. A 10-day trial period is available but actual subscription costs from $29 to $49 monthly.

You can find below FREE Reference Material on ASP.NET MVC5:

In order to pass exam, you need to be practically strong on these Technologies and above tutorials uses fully practical approach with code samples. Top 10 ASP.NET MVC Interview Questions discusses core ASP.NET MVC concepts in much simpler way.

Microsoft Virtual Academy video lessons are also very helpful to start with ASP.NET MVC4 because it discusses concepts in good detail. Please follow here to get access to  Video Tutorials.

Update: You can download you FREE copy of eBook “Programming ASP.NET MVC 5” on ASP.NET MVC 5 by Nimit Joshi. [Download eBook here].Programming ASP.NET MVC 5

This book is a good reference for MVC5 and follows a practical approach covering following topics taken AS IS from Book’s Table of Contents:

  • Getting Started with ASP.NET MVC 5
  • Working with Database
  • Editing Application
  • Working with External Authentication
  • Entity Framework Database First Approach
  • IIS Hosting and Publishing of Application
  • Introduction of ASP.NET SignalR

Security being a very important topic, Microsoft has given it a share of 20-25% in MCSD Certification exam. It covers all important security features including authentication, authorization and data integrity. So, I find the following good material on Security:

Free Online Tests

You can find Online Quizzes on Web Development Tutorial to test your knowledge on different web technologies including Microsoft ASP.NETASP.NET MVCHTML5ASP.NET AJAX and jQuery etc. You can take ASP.NET MVC and HTML5 free online quizzes to improve your skill for Exam: 70-486. Also, at the end of the test you can follow recommended study material to further enhance your skill. Later appear again to verify improvements. You can follow Web Development Free Online Tests here.

Online Practice Exam: 70-486

Before appearing for any actual Certification Exams, it’s always recommended to verify your skills and preparation with Exam Simulators available online because these exam simulators gives you almost same experience as that of actual exam. Following are good Online Practice Exam for 70-486 available with real world scenarios and examples:

  • Online Practice Exam: 70-486  (Developing ASP.NET MVC Web Applications) by Web Development Tutorials
    • Good Pool of Questions and updating on regular basis.
    • Real time practical scenario-based Questions
    • Cost you only $1.99 instead of $4.95 [Regular Price].
  • Practice Tests for Exam: 70-486 (Developing ASP.NET MVC Web Applications) by MeasureUp
    • Good Pool of Questions with real world scenarios
    • Download all questions option (costs $109)
    • It costs between $79 to $109 for different available options
  • Exam: 70-486 (Practice Exam and Quick Preparation Tips) by Self Test Training
    • Total Questions = 104
    • Downloadable PDF Questions List
    • Downloadable Practice Exam Software
    • Price
      • PDF Question and Answers list costs $59
      • PDF with Practice Test costs $99

Above shared material is really helpful to prepare for Exam: 70-486 (Developing ASP.NET MVC Web Applications). Prepare well before appearing for actual exam. I’ll keep updating this post to add more helpful material available online.

All about ASP.NET MVC Controllers and Action Methods

ASP.NET MVC application uses routing rules defined in Global.asax to find out the appropriate Controller and pass the request to it. The Controller receives the request sent by the client and further calls appropriate Model that interact with database and fetches data back to Controller. Controller calls respective View and pass data which is further rendered to client as response. For more details about MVC Routing, please follow ASP.NET MVC Tutorial here.

Below is the pictorial view of above discussion.

ASP.NET MVC

After examining the above diagram, we can conclude that a Controller in MVC is performing the following tasks:

  • Receiving requests coming from client
  • Demanding the model for data or updates on data
  • Providing data to appropriate view for rendering response

By performing above mentioned tasks, a controller basically facilitates to achieve loose coupling between model and View which is highly desirable for Object Oriented Systems.

If we dive deeper to understand about controller, it’s basically a class inheriting from System.Web.Mvc.Controller and placed under Controllers folder. A public method inside a controller class is considered to be a Controller’s Action Method. Each client request reaching Controller is for a specific Action Method. A Controller class can have multiple action methods that are responsible for performing certain operations depending upon the client action. Please look into code for a very simple controller i.e. ProductController.Controller in ASP.NET MVC
Every Controller should have at least one action method. Here Index() is the default action method for ProductController controller. It will be invoked if no action is provided explicitly by the client.

Note: As discussed above that a public method inside a controller is considered to be an Action Method. But if we explicitly don’t want a public method to be an Action Method, we will mark it as Non Action attribute as:

More on ASP.NET MVC Action Methods:

In above code, ProductController has only one default Action Method. In order to fulfill different client requests, our ProductController class can have more Action Methods for all desired user actions as:MVC Action Methods

  • Index() – To get all Products list.
  • Details(int? Id) – To get a specific Product details.
  • Create() – Add a new Product.
  • Edit(int? Id) – Update an existing Product.
  • Delete(int? Id) – Delete an existing Product.

Calling Pattern of a Controller’s Action Method is as:
http://Server:Port/{Controller}/{Action}/{Id}

For Example, client can call our ProductController’s Action Methods as:

  • Index()  as:
    http://localhost:XXXX/Product/Index
    or simply http://localhost:XXXX/Product/
  • Details(string Id) as:
    http://localhost:XXXX/Product/Details/5
  • Create() as:
    http://localhost:XXXX/Product/Create
  • Edit(string Id) as:
    http://localhost:XXXX/ProductController/Edit/5
  • Delete(string Id) as:
    http://localhost:XXXX/ProductController/Delete/5

All these above action methods can be invoked by using any HTTP request method (like GET, POST, PUT, DELETE). By default, ASP.NET MVC framework does not apply any restriction. But we can restrict our action method to be invoked by a specific HTTP request method. We can apply such restriction by using HTTP request method attributes as HttpGet, HttpPost, HttpPut and HttpDelete.

How to change an Action Method’s Name?

In ASP.NET MVC, we can use ActionName attribute to give a changed name to our action methods. Caller(the client) will be using the name given in ActionName attribute as:

Now, the Index() action method will be called by name “GetAllProducts”.

Action Results and Helper Methods

All above Action methods perform certain operations by interacting with Model and return output data back to View. Return type of an action method in ASP.NET MVC is called an action result. ASP.NET MVC framework provides an abstract class named “ActionResult” which is basically a base class for all action results. Also, there are many built-in action result types derived from ActionResult class like ViewResult, PartialViewResult, RedirectResult etc.
Following code snippet clearly shows that Index() action method has a return type ActionResult and View() as Helper Method.
Action Results & Helper Methods
Return type can be any of the derived type but it all depends what task an action method is performing. For example,

  • In case of redirect to another action method, Helper method will be Redirect() and action result will be RedirectResult(derived class of ActionResult).
    public RedirectResult Redirect()
    {
         return Redirect(“AboutMe”);
    }

     

  • Similarly, to return a JSON object, Helper method will be Json() and action result will be JsonResult (derived class of ActionResult).
    public JsonResult GetJsonData(List<Product> product)
    {
         return Json(data: product[0].Description.ToString());
    }

Following is a list of other important Action Result Types with Helper Methods:

Action Result

Helper Method

Short Description

ViewResult View It renders a view as a web page
PartialViewResult PartialView It renders a PartialView.
RedirectToRouteResult RedirectToAction or RedirectToRoute It redirects to another action method.
JavaScriptResult JavaScript It returns a script that can be executed on client.
FileResult File It returns a binary output to for response.
ContentResult Content To return user-defined content type.
Please follow here for a complete list of all ActionResult types with respective Helper methods.
Hopefully, it will be easy to implement ASP.NET MVC application. So, let’s create your first ASP.NET MVC 5 application with Entity Framework step by step.

Other Related Articles:

ASP.NET Online Test

Top 10 Interview Questions and Answers Series: