Learning MVC: Passing Data among MVC Components

I've been trying to learn MVC for quite a while now and the thing I was stuck on for a WHOLE week was how to pass data from Views to Controllers to Models to Controllers and so on, saw lots of videos and tutorials until I Finally did it!

Why I'm Learning MVC?

I and my friend are working on a blog builder project that will help you create your very own blog site almost like hashnode itself.

The reason is this will help us learn the true power of MVC from its deeper and meaning full concepts like routing and attributes.

MVC is considered hard but is easy once you get the hang of it, also prior knowledge of the Dot NET world surely helps.

My Knowledge on the topic came from my past project in which I made a Crypto Trading System using the Coin Gecko API and the ASP.NET web forms (I'll Upload the project on Git HUB soon...)

Anyway here's how I finally figured out how the passing of the arguments and data among the MVC components is taking place.

Output:

View Code:

@model OuglaWebApp.Models.testModel

<div class="row">


    <div class="col-lg-6 col-md-6 col-sm-12">
        <h1>Get your Blog Live in under 10 minutes using Ougla!</h1>
        <p>
            @Model.Name
            @Model.sitename
            @Model.password
        </p>
    </div>


    <div class="col-lg-6 col-md-6 col-sm-12 justify-content-center align-content-center">
        <form class="border p-4" method="post" asp-action="output" asp-controller="Home">
            <div class="text-center">
                <h1>Sign-up</h1>
            </div>

            <label class="form-label">Name: </label>
            <input class="form-control" type="text" asp-for="@Model.Name"/>

            <label class="form-label">Site Name: </label>
            <input class="form-control" type="text" asp-for="@Model.sitename" />

            <label class="form-label">Password: </label>
            <input class="form-control" type="password" asp-for="@Model.password" />

            <label class="form-label">Retype Password: </label>
            <input class="form-control" type="password"  />

            <div class="text-center">
                <input class="btn btn-primary mt-2" type="submit" value="Sign-up" />
            </div>

        </form>
    </div>
</div>

Controller Code:

        testModel obj = new testModel();
        //Get Controller
        public IActionResult Index(testModel data)
        {
            return View(data);
        }
        [HttpPost]
        public IActionResult output(testModel data)
        {
            var d = data;
            return RedirectToAction("Index",data);
        }

        public IActionResult Privacy()
        {
            return View();
        }

Model Code:

using System.ComponentModel.DataAnnotations;

namespace OuglaWebApp.Models
{
    public class testModel
    {
        public string Name { get; set; }
        [Key]
        public string sitename { get; set; }
        public string password { get; set; }
    }
}