I wanted to take a moment to say how I decided it. After playing a little more, I realized that in fact I am not very clear about my problem. Basically, all I'm trying to do is insert an MVC form inside the Partial View macro so that it can be used in the content of the page (not built into the template).
I could get this solution to work, but I really didn't like how much logic the author puts into the View file. So I adapted his solution this way:
Partial macro view (cshtml) file:
@inherits Umbraco.Web.Macros.PartialViewMacroPage @using Intrepiware.Models @{ bool isPostback = !String.IsNullOrEmpty(Request.Form["submit-button"]); if(isPostback) { @Html.Action("CreateComment", "ContactSurface", Request.Form) } else { @Html.Partial("~/Views/Partials/ContactForm.cshtml", new ContactFormModel()) } }
Partial View File (cshtml):
@using Intrepiware.Models @using Intrepiware.Controllers @model ContactFormModel <p> <span style="color: red;">@TempData["Errors"]</span> </p> <p> @TempData["Success"] </p> <div id="cp_contact_form"> @using(Html.BeginUmbracoForm("CreateComment", "BlogPostSurface")) { @* Form code goes here *@ }
ContactSurfaceController.cs file:
public class ContactSurfaceController : Umbraco.Web.Mvc.SurfaceController { [HttpPost] [ValidateAntiForgeryToken] public ActionResult ubCreateComment(ContactFormModel model) { if (processComment(model) == false) return CurrentUmbracoPage(); else return RedirectToCurrentUmbracoPage(); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult CreateComment(ContactFormModel model) { if(processComment(model) == true) { TempData["Success"] = "Thank you for your interest. We will be in contact with you shortly."; ModelState.Clear(); } return PartialView("~/Views/Partials/ContactForm.cshtml"); } private bool processComment(ContactFormModel model) {
The controller is designed in such a way that the form can be embedded either in the template or in the Partial View macro. If it is embedded in the template, the form should be placed on ubCreateComment ; if it is in a macro, send a message to CreateComment .
I am pretty sure that there is a better / more correct way to do this, but I did not have enough time to work on the project. If anyone has a better solution, submit it!
One final question / note: you will notice that partial view macros point Request.Form to ContactSurfaceController.CreateComment and MVC, magically serializing it for me. It's safe, huh? If so, is it not MVC rock? :)