ASP.NET MVC OutputCache with POST Controller Actions

I am new to using attribute OutputCachein ASP.NET MVC.


Static Pages

I enabled it on static pages on my site with code such as:

[OutputCache(Duration = 7200, VaryByParam = "None")]
public class HomeController : Controller
{
    public ActionResult Index()
    {
        //...

If I understood correctly, I made the entire controller cache in 7200 seconds (2 hours).


Dynamic pages

However, how does it work with dynamic pages? By dynamics, I mean where the user should submit the form.

As an example, I have a page with an email form. Here is what this code looks like:

public class ContactController : Controller
{
    //
    // GET: /Contact/

    public ActionResult Index()
    {
        return RedirectToAction("SubmitEmail");
    }

    public ActionResult SubmitEmail()
    {
        //In view for CAPTCHA: <%= Html.GenerateCaptcha() %>
        return View();
    }

    [CaptchaValidator]
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult SubmitEmail(FormCollection formValues, bool captchaValid)
    {
        //Validate form fields, send email if everything good...

            if (isError)
            {
                return View();
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }

    }

    public void SendEmail(string title, string name, string email, string message)
    {
        //Send an email...

    }
}

What happens if I apply OutputCache to the entire controller here?

Will the HTTP POST submission form be issued? In addition, my form has a CAPTCHA; will anything change in the equation?

, ?

.

+5

All Articles