0% found this document useful (0 votes)
5 views4 pages

? Project Name - Contact Form App - Netmvc

The document outlines the creation of a Contact Form App using ASP.NET Core MVC, allowing users to submit and view messages without a database. It details the steps to set up the project, create the model, controller, and views necessary for the application. Users can navigate to the /Contact route to submit messages and view them in an in-memory list.

Uploaded by

gajndra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

? Project Name - Contact Form App - Netmvc

The document outlines the creation of a Contact Form App using ASP.NET Core MVC, allowing users to submit and view messages without a database. It details the steps to set up the project, create the model, controller, and views necessary for the application. Users can navigate to the /Contact route to submit messages and view them in an in-memory list.

Uploaded by

gajndra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

📘 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

You might also like