Returning a Partial View (ActionResult HandleFormPost(ContactModel model))
Hi all,
I have a pop-up form as follows (which uses FancyBox to display a certain DIV in the DOM that is previously hidden and contains a Partial):
In my surface controller I have:
/// <summary>
/// For more information, see:
/// http://stackoverflow.com/questions/6282049/form-with-attachments-upload-and-email-sending
/// </summary>
/// <param name="model">The popup form model</param>
/// <returns>The ActionResult</returns>
public ActionResult HandleFormPost(PopupFormModel model)
{
try
{
if (ModelState.IsValid)
{
// Then good to submit.
var sb = new StringBuilder();
sb.AppendFormat("<p>Name: {0}</p>", model.Name);
sb.AppendFormat("<p>Email: {0}</p>", model.Email);
sb.AppendFormat("<p>{0}</p>", model.Message);
using (var client = new SmtpClient())
{
EnquiryType enquiryType = Enquiries.GetEnquiryByID(model.EnquiryType);
if (enquiryType != null)
{
var mail = new MailMessage();
mail.To.Add(enquiryType.EmailAddress);
mail.Subject = "Website Form Submission";
mail.Body = sb.ToString();
if (model.Attachment.HasFile())
{
var attachment = new Attachment(model.Attachment.InputStream, model.Attachment.FileName);
mail.Attachments.Add(attachment);
}
client.Send(mail);
return PartialView("Webtechy_Success");
}
return PartialView("Webtechy_Error");
}
}
return CurrentUmbracoPage(); // Not valid, there is something they need to fill in.
}
catch(Exception ex)
{
return PartialView("Webtechy_Error");
}
}
However, rather than just updating the contents of the pop-up box, it's returning the Partial view taking up the whole page.
Returning a Partial View (ActionResult HandleFormPost(ContactModel model))
Hi all,
I have a pop-up form as follows (which uses FancyBox to display a certain DIV in the DOM that is previously hidden and contains a Partial):
In my surface controller I have:
However, rather than just updating the contents of the pop-up box, it's returning the Partial view taking up the whole page.
Any ideas greatly appreciated.
Regards,
Ben
Hi - did you figure this out. Im having the same problem with my action result returning a partial view but it takes the whole page.
Ben,
Basically you need to submit to the controller via Ajax and depending on the result show an appropriate response container.
I'm not at my desk now but if you look at the example in the fancybox site you can see what I mean:
Step 5: http://fancybox.net/blog
I've got something like this in one of my sites, when I'm back at my desk tomorrow morning I'll find it for you and share the code!
Jon
is working on a reply...