Hello, I'm trying to create contact form on a bazaar store. I've done very similar without issue on other Umbraco sites. I get a 'No parameterless constructor' error.
I've been unable to identify what's causing this, despite stepping through with visual studio.
Here's the format:
New document type: 'ContactForm'
Hijacked the route:
public class ContactFormController : RenderControllerBase
{
public override ActionResult Index(RenderModel model)
{
var viewModel = new ContactUsModel(model.Content); { };
viewModel.CurrentCustomer = this.CurrentCustomer;
return View(viewModel.ThemeViewPath("ContactForm"), viewModel);
}
}
Model (inherits from MasterModel for the ICustomerBase)
public class ContactUsModel : MasterModel
{
public ContactUsModel(IPublishedContent content) : base(content)
{
}
[Required]
public string Name { get; set; }
[Required]
public string TelephoneNumber { get; set; }
[EmailAddress]
public string Email { get; set; }
[Required]
public string Message { get; set; }
public int ThankYouPage { get; set; }
}
Creating custom contact form, on Bazaar store site
Hello, I'm trying to create contact form on a bazaar store. I've done very similar without issue on other Umbraco sites. I get a 'No parameterless constructor' error.
I've been unable to identify what's causing this, despite stepping through with visual studio.
Here's the format:
New document type: 'ContactForm'
Hijacked the route:
Model (inherits from MasterModel for the ICustomerBase)
ContactForm view:
Partial view:
At this point the page loads as expected, with the contact form. On submit of the form I receive the 'No parameterless constructor'
Surface controller - my breakpoints aren't being hit on this class..
Would appreciate some assistance here guys.
cheers
@Jason,
I think the problem is you are posting a model that inherits from PublishedContentModel.
It would probably be more straight forward to publish a simple POCO model (one that has a default constructor with no parameters).
In your contact page, you could either add a ContactFormModel and pass it to partial which had the form or use an Html.Action to render the form ...
@Rusty
Many thanks. I went ahead and created a POCO model as suggested - working fine now.
cheers
is working on a reply...