Creating an ASP.Net MVC 3 application

If you want to explore any software framework the best thing is, just go ahead and create a small project and understand how the framework helps you in your development efforts. Anybody who is into web development must know how an ASP.Net application works. The prior knowledge of ASP.Net application is beneficial to create MVC based application but not necessary. In this article, we will create a MVC 3 application, a Controller and a View.

To create a MVC 3 web application, open VS 2010 and follow the below steps.

Select File - New - Project option. In the New Project dialog, Select the item ASP.Net MVC 3 web applictaion as shown in Figure.

New Project dialog, Select the item ASP.Net MVC 3 web applictaion

Give a name to the project and click the ok button. Another dialog appears displaying 3 project templates.

dialog which displays 3 mvc project templates

They are:
  • Empty
  • Internet application
  • Intranet application


Select Empty project template and view engine as Razor and press ok button. The default directory is created for MVC 3 application and can be seen in the solution explorer.

If you select project template as Empty, the minimum required files (Global.asax, web.config and java script libraries that supports AJAX and JQuery under Script folder) and folders ( Controllers, Models, Views, Scripts) are created to run the MVC 3 application as shown in the Figure.

mvc application project structure in the solution explorer

If Internet application project template is selected, it includes all the files and folders created earlier and also under Controllers directory, the two files AccountController.cs and HomeController.cs and required views for these two controllers are created. These two controllers manage user´s login details and authentication.

The Intranet application project template is chosen to provide windows-based authentication where all users are authenticated by using Active Directory managed by windows server. For this article, I have chosen Empty project template. There is no default controller created in the solution explorer. We will create one controller now.

Creating the Controller

In the solution explorer, select Controllers folder and select Add - Controller option. The Add Controller dialog box appears.

Add Controller dialog box

Give Controller name as HomeController and in the Scaffolding options section, select the Empty controller as template and click the Add button. The name of controller name is suffixed with Controller word. Even though it is not compulsory, it is better to follow the MVC conventions. Visual studio creates the Homecontroller.cs file as shown below. As you can see the HomeController class is derived from Controller class and Index() is the action method.

Homecontroller file derived from Controller class and with the Index() action method

Observe the below picture.

Add Controller dialog box with different Sacffolding options

If you select the option - Controller with empty read/write actions as template in the Sacffolding options section of the Add Controller dialog box, the controller class is created with empty common functionalities like Create, Details, Edit and Delete Action methods.
Note:- 1.Depends on the option selected in the Template dropdownlistbox, the controller class is created with some default Action methods.

Create and render a View

After that, we need to create a view to give HTML response to the browser. When action method Index() is executed, View() method is called and default view is rendered. As we have created an Empty project, there is no default view for the Index action method. We will create a view by right-click on the Index() method and select Add View option. The Add View dialog box is displayed.

The Add View dialog box to create a view in the mvc application

The Index.cshtml file is created under Views sub directory as shown in Figure.

The Index.cshtml file under Views sub directory

Open the Index.cshtml and type the text as shown below.

Index.cshtml with some text typed

Observe that the Index() action method´s return type is ActionResult. This is the general result type that can have several subtypes. Eventhough we have not mentioned any name of View to be rendered in the Index() action method, based on MVC naming conventions, Index method finds the corresponding view with the name as the action method in the Views directory, that is index.cshtml. The next step is run the project and the output is displayed.


cover image of azure cloud book

Develop Azure Applications

Azure Cloud is gaining popularity and is competing with Amazon Elastic Cloud and Google Cloud for a spot in the billion dollar Cloud computing space.

With this book learn how to use - Table (an Azure Table is different from a SQL Server Table), Queue, Blob storage services, use your local machine to create an Application and a Service, how Azure splits a Table to achieve Load Balancing, Scalability based on the Partition Key, AppFabric Service Bus, Access Control Service, role of Fabric Controller, features of Azure SQL Database and Content Delivery Network.

Many have mastered Cloud Programming and are enjoying the benefits. Why not you?

View Highlights » View Contents »
cover image of foundation database programming book

Create your Own Accounting Software

A foundation book to Master Accounting Software Development, VB.Net, C# and OOPs programming. Detailed explanation of the Accounting domain for programmers is included. SQL and ADO.Net is also covered in detail.

This book gives you a strong foundation in Application Development.

A thorough understanding of the contents will enable you to grasp the topics covered in the accompanying books quite easily. This is because, the accounting domain is dealt with great detail in this book.

The ideal book to get started with application development in the .Net world.

View Highlights » View Contents »

cover image of asp.net book

Create your Own WEB ERP Software using ASP.Net

This book opens you to the Web. Using ASP.Net, C# and SQL Server as the tools, you will learn to build a Multi Tier Web Application as recommended by Microsoft. You will learn implementing inline GridView control, Transaction Management for a layered Web Application, build Data Access component and a Business Layer component.

Opens you to a world of opportunities. You will be able to develop a Web ERP application including all the five modules and learn how to use the TreeView control and GridView control to implement transactions such as Purchase Invoice, Sales Order and Sales Invoice.

View Highlights » View Contents »
cover image of entity framework book

ASP.Net MVC 5 Application Development Using Entity Framework 6 and VS 2015

Entity frameworks is the latest buzz in .Net programming and is the data access technology for Microsoft OS based hand held devices and web applications. Learn to integrate EF into an ASP.Net Application and MVC application. Create, explore and query the Entity Data Model. Learn how to use ObjectDataSource control and GridView control in an ASP.Net Application.

Also, learn to build Three-Tier ASP.Net application, create a business-class, implement methods in the class to perform CRUD operations and bind a GridView to the ObjectDataSource control. Learn how to handle concurrency and managing Transactions.

View Contents »