Integrating a Contact Form With Custom (surface) Controller
All,
We are trying to get our contact form working, with an MVC SurfaceController. Everything renders out correctly, but we are unable to get the form to post back on a submit. Code below. The controller and the model are i nthe App_Code folder.
CONTROLLER
public class ContactSurfaceController : Umbraco.Web.Mvc.SurfaceController
{
[HttpGet]
public ActionResult ContactForm()
{
return PartialView("Contact", new ContactModel());
It might be because you have both the GET and POST action methods named the same. This allowed in MVC (and C# of course) due to the method overloading, but Umbraco can get confused with this. There's an attribute [NotChildAction] you can add to the POST method. And for completeness, you should also really add [ChildActionOnly] to the GET.
Integrating a Contact Form With Custom (surface) Controller
All,
We are trying to get our contact form working, with an MVC SurfaceController. Everything renders out correctly, but we are unable to get the form to post back on a submit. Code below. The controller and the model are i nthe App_Code folder.
CONTROLLER
public class ContactSurfaceController : Umbraco.Web.Mvc.SurfaceController
{
[HttpGet]
public ActionResult ContactForm()
{
return PartialView("Contact", new ContactModel());
}
[HttpPost]
public string ContactForm(ContactModel contact)
{
//Do Stuff Here
return "Success";
}
}
VIEW
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = "Master.cshtml";
}
<div id="content" class="textpage">
<h3>@CurrentPage.Title</h3>
<h4>@CurrentPage.subTitle</h4>
<div class="full_blue_box" style="min-height: 350px;">
<div style="width: 250px; float: left; padding-right: 25px; border-right: 1px solid #fcfcfc;">
<h2><span style="color: #ffffff;">Get in Touch</span></h2>
@*@Umbraco.RenderMacro("ContactForm", new { Subject = "Subject Parameter", YourEmail="[email protected]" })*@
@Html.Partial("_ContactForm", new ContactModel())
</div>
<div style="width: 520px; float: right; padding-left: 25px;">
<h3><span style="color: #ffffff;">Office address</span></h3>
@Umbraco.Field("content")
</div>
</div>
</div>
PARTIAL VIEW
@model ContactModel
@using (Html.BeginUmbracoForm<ContactSurfaceController>("ContactForm"))
{
<fieldset>
<legend>Your details</legend>
<form id="contactForm">
<p>
@Html.TextBoxFor(model => model.Subject, new { placeholder = "Subject" })
@Html.ValidationMessageFor(model => model.Subject)
</p>
<p>
@Html.TextBoxFor(model => model.Email, new { placeholder = "Email Address" })
@Html.ValidationMessageFor(model => model.Email)
<p>
@Html.TextAreaFor(model => model.Message, new { placeholder = "Your Message" })
@Html.ValidationMessageFor(model => model.Message)
<input type="submit" value="Send Email"/>
</form>
</fieldset>
}
CONTACTMODEL
public class ContactModel
{
public string Subject { get; set; }
public string Email { get; set; }
public string Message { get; set; }
}
It might be because you have both the GET and POST action methods named the same. This allowed in MVC (and C# of course) due to the method overloading, but Umbraco can get confused with this. There's an attribute [NotChildAction] you can add to the POST method. And for completeness, you should also really add [ChildActionOnly] to the GET.
See here for details.
Hope that helps.
Andy
Thanks - this definitely got us going the right direction. We will post our solution in the future. -David
So did you get it working and can you post your solution?
Thanks
is working on a reply...