I've been trying to teach myself MVC, and have replicated the Contact Us form calling it Request a Demo.
I have added it to the route, and controller. I have built a new model, validator, and view.
I am using CommonController.cs, in there it has
//contact us page
public ActionResult ContactUs()
{
var model = new ContactUsModel()
{
Email = _workContext.CurrentCustomer.Email,
FullName = _workContext.CurrentCustomer.GetFullName(),
DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage
};
return View(model);
}
I replicated this adding to CommonController.cs
//request a demo page
public ActionResult RequestADemo()
{
var model = new RequestADemoModel()
{
Title = _workContext.CurrentCustomer.Title,
FirstName = _workContext.CurrentCustomer.FirstName,
Surname = _workContext.CurrentCustomer.Surname,
Company = _workContext.CurrentCustomer.Company,
Premises = _workContext.CurrentCustomer.Premises,
Street = _workContext.CurrentCustomer.Street,
Street2 = _workContext.CurrentCustomer.Street2,
Town = _workContext.CurrentCustomer.Town,
County = _workContext.CurrentCustomer.County,
Postcode = _workContext.CurrentCustomer.Postcode,
Telephone = _workContext.CurrentCustomer.Telephone,
DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage
};
return View(model);
}
The problem with this is it uses _workContext.CurrentCustomer, and expects all my fields to be part of the Customer class. That's ok, I can add all those properties. My next problem is if I do that it expects to find all those properties in the Customer table in the database.
Server Error in '/' Application.
Invalid column name 'Title'.
Invalid column name 'Initial'.
Invalid column name 'Surname'.
Invalid column name 'Company'. .......
I think I'm going wrong my using _workContext.CurrentCustomer in the controller. Once I have this working I would like to build a plugin to release to the community. Should I write my own controller instead?
Can anyone advise please?
Thank you