pure mvc widget with form submit - caching problem - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

pure mvc widget with form submit - caching problem

  • pure mvc widget with form submit - caching problem
  • Hi,

    I have been developing on ASP.Net since the early days (2002), a few years ago I started with ASP.Net MVC and just recently (1 week :-) ago) started with the implementation of a Sitefinity CMS for one of our customers.

    Because I, and the company I work for, love ASP.Net MVC, we are using Pure MVC mode in SiteFinity.

    I am currently developing a small MVC widget that contains a simple form (just for testing purposes), my Controller looks like this:

    [ControllerToolboxItem(Name = "SimpleFormWidget", Title = "Simple Form",
            SectionName = "Forms")]
        public class SimpleFormWidgetController : Controller
        
            public ActionResult Index()
            
                var model = new SimpleFormWidgetModel();
                return View("Default", model);
            
     
            [HttpPost]
            public ActionResult Index(SimpleFormWidgetModel model)
            
                if (ModelState.IsValid)
                
                    model.IsSubmitted = true;
                
     
                return View("Default", model);
            
        

    My model looks like this:

    public class SimpleFormWidgetModel
       
        
           public bool IsSubmitted get; set;
     
           [Required]
           public string Name get; set;
     
       

    My view looks like this:

    @using Telerik.Sitefinity.UI.MVC;
    @model SitefinityWebApp.Mvc.Models.CallMeBackWidgetModel
                
    @if (Model.IsSubmitted)
        <p>
            Thank you for submitting the form.</p>
    else
        using (Html.BeginFormSitefinity())
        
            <p>
                @Html.LabelFor(m => m.Name)
                @Html.TextBoxFor(m => m.Name)
            </p>  
         
            @Html.ValidationSummary(false)
         
            <button type="submit">
            Send</button>
        

    I have placed the widget on a page, placed a breakpoint at the start of the Index method with the [HttpPost] attribute.

    When I start to debug the web application and go to the page that contains the widget, the page is rendering fine.

    When I submit the form, the breakpoint I have set is hit and I can see that my ModelState is invalid because I have not entered a name (which is required (see the required attribute on the model).

    The page now displays the validation summary.

    So far, so good.

    Now comes the problem: When I enter a name and submit the form again, the breakpoint is not hit and the validation summary is still being displayed. SiteFinity seems to have cached the previous post action and renders the cached result instead of handling the post itself in the controller action.

    Is this a bug or did I just forget to do something to prevent this from happening?

    My current Output Cache Settings are:

    Enable Output Cache: False
    Enable Client Cache: False
    Default Output Cache Profile: No Caching
    Default Client Cache Profile: No Caching

    But even with output caching enabled, a POST should, ofcourse, always be handled by the Action on my controller.

    I also don't know how to make sure the cache is no longer used, the only thing I can do to re-test this and make sure the cache is no longer used, is by changing the port number on the ASP.Net Development Server. 

    I am using SiteFinity version 5.4 with Visual Studio 2010 SP1 with the built-in Visual Studio Development Server (Cassini).

    I hope someone can help me out.

    Many thanks in advance!

    Marien Brethouwer
    Sixtyseven

  • Hi Marien,

    For Pure mode use Html.BeginForm as described in this documentation. To avoid MVC cache above the controller action method use as an attribute
    [System.Web.Mvc.OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]

    Kind regards,
    Stanislav Velikov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Hi Stanislav, 

    Thank you for your reply. 

    I had changed Html.BeginForm to Html.BeginFormSitefinity because I got a javascript error message when editing the page with the widget on it that contained the Html.BeginForm.

    I have tried what you have described: I changed Html.BeginFormSitefinity to Html.BeginForm, put the [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")] attribute on both the Index methods (also the one with [HttpPost] attribute, and this is what happened:
    • breakpoint is hit on Index() action method, the first time it is called.
    • it doesn't hit the breakpoint in the [HttpPost] Index method on the first form submit !
    • breakpoint is not hit on Index() action method, the second time it is called.
    When I change back Html.BeginForm to Html.BeginFormSitefinity() and change the port number on the web development server (to prevent the cache from being used), the breakpoint on the [HttpPost] index method is hit on the first form submit, but it is not hit on the second form submit.

    In short, the OutputCache attribute doesn't seem to have any effect on the caching of the action result.

    I hope you can give me an alternate solution.

    Many thanks in advance,

    Kindr regards,

    Marien





  • Hi,

    I believe the problem is connected with way the postback on the Html.BeginFormSitefintiy is used at your MVC classes. Can you also check if changint the page cache will have effect in addition to already having
    [System.Web.Mvc.OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
    in the Action methods of the controller, go to the page where the mvc widget is used and expand Actions->Title and Properties and set the Caching options for the page to "No Cache", if this too have no effect can you provide the modle view and controller where the problem occurs?

    Kind regards,
    Richard Moore
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • @Marien: I'm sure you tried to turn-off the cache on a global level? (Settings -> System -> Output Cache?

    Just my 2 cnts... :)
  • Hi Daniel,

    That was one of the first things I tried. Didn't help either.

    I created a support ticket for this issue on the 29th of march and it's still open, Telerik expects to have this bug fixed in SP1 for Sitefinity 6.
  • You sure they didn't say SP2 or 6.1?

    www.sitefinity.com/.../sitefinity-6-0-sp1-released
  • Hi Steve,

    That's interesting, in the last post of our support ticket Boyan Barnev wrote that the bug has officially been scheduled for the upcoming ServicePack.
     
    He wrote this on may 7th, so I assumed it would be SP1. The bug is not listed as fixed and our support ticket also has not been updated. I will send a reply on our support ticket to get some clarification.
  • Not ever fix is always in the notes, keep us updated please :)
  • I would also like an update on this!
  • I haven't received an update yet from Telerik. Still the same status as one month ago.
  • Hello,

    The problem is now in the stage of testing in order to be added in the next sitefinity release this month in July.

    Regards,
    Stanislav Velikov
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Hi Stanislav,

    Thanks for the update.

    Kind regards,

    Marien