Build a Website in Visual Studio 2010 ASP.NET, C#, and MVC3.

To build a website using Visual Studio 2010 is very straight forward. You can can powerful results for very little coding effort. This article provides the steps for building a website using Visual Studio 2010 Professional, ASP.NET 4.0, C# 2010, MVC3, and SQL Server 2008 R2 Express Edition.

If you are a student, you can obtain Visual Studio 2010 Professional for free by visiting SQL Server 2008 R2 Express can be obtained by visiting  Microsoft.  Make sure these are installed before continuing with this article. Also, you will need to make sure the instance .\SQLEXPRESS is up and running.

Create an empty database. Open up the Visual Studio 2010 Command Prompt, and type aspnet_regsql. Go through the wizard that pops up to add the Membership API tables to the database.

Create a new Visual Studio 2010 C# ASP.NET MVC3 Website. Change the connection string in the Web.config file by appending the attribute “MultipleActiveResultSets=True” to the end of it. I have called my database Hospital, and the connection string is: "Data Source=.\SQLEXPRESS;Initial Catalog=Hospital;Integrated Security=True;Pooling=False;MultipleActiveResultSets=True;".

Open up the Package Manager Console. Type Install-Package MvcScaffolding. This will install the MvcScaffolding libraries necessary for the next steps.

In the Models folder of your Visual Studio project, add a class and call it HospitalModels. Add the following code:

namespace Hospital.Models
public class Specialism
public int Id { get; set; }
public string Name { get; set; }

The above code is a model. In this scenario it is a medical specialism. In the Package Manager Console type Scaffold Controller Specialism. Once scaffolding has been completed, you should see under Views a folder called Specialism, and the following CSHTML files: _CreateOrEdit.cshtml, Create.cshtml, Delete.cshtml, Details.cshtml, Edit.cshtml, and Index.cshtml.

In order for the created pages to be visual accessible via the home page, you need to modify the “_Layout.cshtml” file under the “Views\Shared” folder. Add the following code under the “About” menu item:

<li>@Html.ActionLink("Specialism", "Index", "Specialism")</li>

The first item in the ActionLink is the text that appears as the hyperlink, the second item is the page to display, and the third item is the folder which contains the required file.

Now you are able to run the project. If you have problems running the project, check your connection string and check the instance of SQL Server Express is running.

Hospital specialisms that you can use as sample data: Audiology, Cardiology, Colorectal, Cosmetic Surgery, Dermatology, “Ears, Nose & Throat”, Gastroenterology, General Medicine, Gynaecology (Women’s Health), Infertility Clinic, Joint and Muscle Clinic, Neurology, Obstetric Scanning, Opthalmology, Othorpaedics, Paediatrics, Pain Management, Physiotherapy, Podiatry, Psychological Medicine, Radiology, Respiratory Medicine, Rheumatology, Sexual Health Medicine, Shockwave Therapy, Travel Clinic, Urology, Varicose Veines, and Vasectomy.

You should be able to add, edit, delete, list all items, and view individual items, and all for little coding effort.