Hopefully, one of you guys will be able to point me in the right direction, i have just embarked on my journey to learn c# and .net and I'm in the process of a practice Application that will store contacts/customers, leads, and contracts. I have built a model class with the contact class that stores, recalls, and edits but I need to merge some of this data into the lead section and then store this lead within the contact area.
I've looked online and it suggests using temp data, before researching how to do this I was hoping that you guys may be able to recommend the best solution for a novice and a little insight into how I would implement this.
Any help or advice will be appreciated.
My thoughts process is that I could potentially store all of the data within the one class but I'm assuming this would be a cheat and although it may work I wouldn't work correctly with validations in the forms, ideally, a search area in the lead section would be the best option that would populate the required details into a new lead form.

Jignesh KumarRank #91 · 22.9K reputationPosted Nov 8, 2023, 10:44 PM EST
Hello Spence,
Please try this one,
public class YourModel { public string Key { get; set; } }First View :
public ActionResult FirstView() { var model = new YourModel { Key = "Data to be passed here" }; return RedirectToAction("SecondView", model); }Secon View :
public ActionResult SecondView(YourModel model) { return View(model); }Spencer29 reputationPosted Nov 9, 2023, 4:57 PM EST
Thank you, let me try
Using this method would the presence of the lead be recorded on the contact record?
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.EntityFrameworkCore; using QUESTCRM.Data; using QUESTCRM.Models; namespace QUESTCRM.Controllers { public class ContactsController : Controller { private readonly ApplicationDbContext _context; public ContactsController(ApplicationDbContext context) { _context = context; } // GET: Contacts public async Task Index() { return _context.Contacts != null ? View(await _context.Contacts.ToListAsync()) : Problem("Entity set 'ApplicationDbContext.Contacts' is null."); } // GET: Contacts/Details/5 public async Task Details(int? id) { if (id == null || _context.Contacts == null) { return NotFound(); } var contacts = await _context.Contacts .FirstOrDefaultAsync(m => m.ContactId == id); if (contacts == null) { return NotFound(); } return View(contacts); } // GET: Contacts/Create public IActionResult Create() { return View(); } // POST: Contacts/Create // To protect from overposting attacks, enable the specific properties you want to bind to. // For more details, see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] public async Task Create([Bind("ContactId,FirstName,LastName,CompanyName,Telephone,Mobile,email,WorkEmail,Address1,address2,Town,State,Postcode,ContactType,AccountsRef,CustomerPortal,AccessDocs,PortalEmail,PortalPassword,ContactComments,LeadId")] Contacts contacts) { if (ModelState.IsValid) { _context.Add(contacts); await _context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); } return View(contacts); } // GET: Contacts/Edit/5 public async Task Edit(int? id) { if (id == null || _context.Contacts == null) { return NotFound(); } var contacts = await _context.Contacts.FindAsync(id); if (contacts == null) { return NotFound(); } return View(contacts); } // POST: Contacts/Edit/5 // To protect from overposting attacks, enable the specific properties you want to bind to. // For more details, see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] public async Task Edit(int id, [Bind("ContactId,FirstName,LastName,CompanyName,Telephone,Mobile,email,WorkEmail,Address1,address2,Town,State,Postcode,ContactType,AccountsRef,CustomerPortal,AccessDocs,PortalEmail,PortalPassword,ContactComments,LeadId")] Contacts contacts) { if (id != contacts.ContactId) { return NotFound(); } if (ModelState.IsValid) { try { _context.Update(contacts); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactsExists(contacts.ContactId)) { return NotFound(); } else { throw; } } return RedirectToAction(nameof(Index)); } return View(contacts); } // GET: Contacts/Delete/5 public async Task Delete(int? id) { if (id == null || _context.Contacts == null) { return NotFound(); } var contacts = await _context.Contacts .FirstOrDefaultAsync(m => m.ContactId == id); if (contacts == null) { return NotFound(); } return View(contacts); } // POST: Contacts/Delete/5 [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] public async Task DeleteConfirmed(int id) { if (_context.Contacts == null) { return Problem("Entity set 'ApplicationDbContext.Contacts' is null."); } var contacts = await _context.Contacts.FindAsync(id); if (contacts != null) { _context.Contacts.Remove(contacts); } await _context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); } private bool ContactsExists(int id) { return (_context.Contacts?.Any(e => e.ContactId == id)).GetValueOrDefault(); } } }using System.ComponentModel.DataAnnotations; using System.ComponentModel; namespace QUESTCRM.Models { public class Contacts { [Key] public int ContactId { get; set; } [DisplayName("First Name")] [Required] public string FirstName { get; set; } [DisplayName("Last Name")] [Required] public string LastName { get; set; } [DisplayName("Company Name")] public string? CompanyName { get; set; } [DisplayName("Main Telephone")] public string? Telephone { get; set; } [DisplayName("Mobile")] public string? Mobile { get; set; } [DisplayName("Main Email")] public string? email { get; set; } [DisplayName("Work Email")] public string? WorkEmail { get; set; } [DisplayName("Address 1")] public string? Address1 { get; set; } [DisplayName("Address 2")] public string? address2 { get; set; } public string? Town { get; set; } [DisplayName("County / State")] public string? State { get; set; } [DisplayName("Postcode / Zip")] public string? Postcode { get; set; } [DisplayName("Contact Type")] [Required(ErrorMessage = "Please select a contact type.")] public ContractType ContactType { get; set; } [DisplayName("Accounts Ref")] public string? AccountsRef { get; set; } [DisplayName("Customer Portal Access")] public bool CustomerPortal { get; set; } [DisplayName("Access to Docs")] public bool AccessDocs { get; set; } [DisplayName("Email")] public string? PortalEmail { get; set; } [DisplayName("Password")] public string? PortalPassword { get; set; } [DisplayName("Comments")] public string? ContactComments { get; set; } public string? LeadId { get; set; } } }