📘 Project Name: Contact Form App
✅ Purpose:
Allow users to:
● Fill out a contact form (Name, Email, Message)
● View all submitted messages (no database—just in-memory list)
🔧 Steps to Create
Step 1: Create Project
● Open Visual Studio
● Select: ASP.NET Core Web App (Model-View-Controller)
● Name it: ContactFormApp
● Click Create
Step 2: Create Model
📄 Models/Contact.cs
csharp
CopyEdit
namespace ContactFormApp.Models
{
public class Contact
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Message { get; set; }
}
}
Step 3: Create Controller
📄 Controllers/ContactController.cs
csharp
CopyEdit
using Microsoft.AspNetCore.Mvc;
using ContactFormApp.Models;
using System.Collections.Generic;
namespace ContactFormApp.Controllers
{
public class ContactController : Controller
{
static List<Contact> contacts = new List<Contact>();
public IActionResult Index()
{
return View(contacts);
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Contact contact)
{
contact.Id = contacts.Count + 1;
contacts.Add(contact);
return RedirectToAction("Index");
}
}
}
Step 4: Create Views
📁 Views/Contact/Index.cshtml
html
CopyEdit
@model List<ContactFormApp.Models.Contact>
<h2>Contact List</h2>
<a asp-action="Create">New Message</a>
<table border="1">
<tr><th>ID</th><th>Name</th><th>Email</th><th>Message</th></tr>
@foreach (var c in Model)
{
<tr>
<td>@c.Id</td>
<td>@c.Name</td>
<td>@c.Email</td>
<td>@c.Message</td>
</tr>
}
</table>
📁 Views/Contact/Create.cshtml
html
CopyEdit
@model ContactFormApp.Models.Contact
<h2>Contact Form</h2>
<form asp-action="Create" method="post">
<label>Name</label>
<input asp-for="Name" /><br />
<label>Email</label>
<input asp-for="Email" /><br />
<label>Message</label>
<textarea asp-for="Message"></textarea><br />
<button type="submit">Submit</button>
</form>
▶️ How to Run:
● Navigate to /Contact
● Press Ctrl + F5
● Submit messages and view them immediately