I've searched all the available tutorials I can find, and I'm still having trouble with Umbraco Surface Controllers. I've created a bare-bones Surface Controller example which sorta works, but has some issues. Here's my code so far, questions to follow:
ContactformModel1.cs:
public class ContactFormModel1
{
public string Email { get; set; }
public string Name { get; set; }
public string HoneyPot { get; set; }
public string Title { get; set; }
public string Last { get; set; }
public string First { get; set; }
public string Addr { get; set; }
public string Phone { get; set; }
public string Time { get; set; }
public string Comment { get; set; }
}
ContactSurfaceController.cs:
public class ContactSurfaceController : Umbraco.Web.Mvc.SurfaceController
{
public ActionResult Index()
{
return Content("this is some test content...");
}
[HttpGet]
[ActionName("ContactForm")]
public ActionResult ContactFormGet(ContactFormModel1 model)
{
return PartialView("~/Views/ContactSurface/Contact1.cshtml", model);
}
[HttpPost]
[ActionName("ContactForm")]
public ActionResult ContactFormPost(ContactFormModel1 model)
{
// Return the form, just append some exclamation points to the email address
model.Email += "!!!!";
return ContactFormGet(model);
}
public ActionResult SayOK(ContactFormModel1 model)
{
return Content("OK");
}
}
Contact.cshtml:
@model ContactFormModel1
@using (Html.BeginUmbracoForm<ContactSurfaceController>("ContactForm"))
{
@Html.EditorFor(x => Model)
<input type="submit" />
}
ContactMacroPartial.cshtml:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@Html.Action("ContactForm", "ContactSurface")
My Questions:
I'm pretty sure that
return ContactFormGet(model)
is wrong in the ContactFormPost method, but everything else I've tried throws an error.When I try
return RedirectToCurrentUmbracoPage()
, I getCannot find the Umbraco route definition in the route values, the request must be made in the context of an Umbraco request
.When I try
return CurrentUmbracoPage()
, I getCan only use UmbracoPageResult in the context of an Http POST when using a SurfaceController form
.The routing appears to work correctly (when I put a breakpoint inside ContactFormPost, the debugger stops there). But when the form comes back, I get the exact values I submitted. I don't see the !!! appended to the email address. (Note, this bit of code is just for debugging, it's not meant to do anything useful).
How do I call the "SayOK" method in the controller? When I change the BeginUmbracoForm method to point to SayOK, I still get stuck in the ContactFormPost method.
I'm sure I'm missing something incredibly stupid, but I can't figure this out for the life of me.