MVC tutorial for beginners

In this tutorial we look at the ASP.NET framework and how we can build web applications using Visual Studio and C#. For our MVC tutorials the basic topics are covered and are listed below.

View the tutorial here at

  • Introduction
  • Hello World
  • Routing
  • Working with Views
  • Working with layouts
  • Connecting to a database
  • Working with forms

Some samples are shown below of the tutorial content.

Simple Hello World

A simple route called HelloWorld in a controller called HomeController.cs

public IActionResult HelloWorld()
    return View();

A simple view that goes with the route above.

    ViewData["Title"] = "HelloWorld";


The output of this is shown below.

Hello World Sample Route

Working with Database

A route in a controller that connects to a database.

public IActionResult Users()
    List<String> emails = new List<String>();
    string connectionString = "server=localhost;user=root;password=;database=wftutorials";
    MySqlConnection conn = new MySqlConnection(connectionString);
    var command = new MySqlCommand("SELECT email FROM musers limit 10;", conn);
    var reader = command.ExecuteReader();
    while (reader.Read())
        var value = reader.GetValue(0).ToString();
        // do something with 'value'
    return View(emails);

The View html template that goes with the route above.

    ViewData["Title"] = "Users";

@model List<String>;


    @foreach (var item in @Model)

The output is shown below

List of users

View the full tutorial at

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s