MVC HTML.RenderAction – Error: Duration must be a positive number

后端 未结 4 1728
没有蜡笔的小新
没有蜡笔的小新 2021-02-13 04:27

On my website I want the user to have the ability to login/logout from any page. When the user select login button a modal dialog will be present to the user for him to enter i

4条回答
  •  無奈伤痛
    2021-02-13 05:17

    In some cases it may be appropriate to just create a second action method, with caching disabled that is called by your primary action.

        /// Use this for normal HTTP requests which need to be cached
        [OutputCache(CacheProfile = "Script")]
        public ContentResult Foo(string id)
        {
            return _Foo(id);
        }
    
        /// Use this for Html.Action
        public ContentResult _Foo(string id)
        {
            return View();
        }
    

    When you need Html.Action you just call _Foo instead of Foo.

    @Html.Action("_Foo", "Bar").ToString();
    

    You can then rely on the parent page to do the caching.


    Another way is to just bypass the whole 'CacheProfile' thing for ActionMethod and use my 'DonutCacheAttribute' instead.

    The 'CacheProfile' for ActionMethods currently only respects the Duration and varyByParam properties - and this method makes it easy to set different caching durations in debug vs. deployment (assuming you're using XDT transformations).

提交回复
热议问题