ASP.NET MVC:表单值在第一次发布后缓存

ASP.NET MVC:表单值在第一次发布后缓存,asp.net,asp.net-mvc,Asp.net,Asp.net Mvc,我可能在这里做了一些完全错误的事情,但是由于某种原因,我在我的一个页面中的表单值在第一篇文章之后被缓存。这不是浏览器的事情,因为即使我打开不同的浏览器,发布的值仍然会被缓存 我的表格很简单: <form action="/post/save" method="post"> <label>Type here whatever you want, quick and without thinking</label> <%= Html.Text

我可能在这里做了一些完全错误的事情,但是由于某种原因,我在我的一个页面中的表单值在第一篇文章之后被缓存。这不是浏览器的事情,因为即使我打开不同的浏览器,发布的值仍然会被缓存

我的表格很简单:

<form action="/post/save" method="post">
    <label>Type here whatever you want, quick and without thinking</label>
    <%= Html.TextArea("Body", new { @class = "post", rows="3" })%>
    <input type="submit" value="Publish" class="big_button red" />
</form>
form对象只有一个ID和一个Body属性。在方法的顶部,这个对象有上一个(实际上是第一个)post请求的主体。有没有我不熟悉的缓存?thx

编辑:

我发现问题的根源是我注册控制器的方式。在我的应用程序\u start中,我有以下代码:

        // This only initialized the Castle IOC container
        DependencyRegistrat.Init();

        DependencyRegistrat.GetDefaultContainer().RegisterAll<IController>(typeof(HomeController).Assembly, ComponentLifecycle.Transient);

        ControllerBuilder.Current.SetControllerFactory(new MyControllerFactory(DependencyRegistrat.GetDefaultContainer()));

您是在添加新文章还是在更新现有文章

如果要更新现有文章,则应首先从存储库检索现有文章


如果您正在创建一个新项目,您应该创建一个项目对象。

问题在于控制器注册。我使用Castle的IOC容器,出于某种原因

这(起作用的):

与此不同(不起作用)

\u Container.AddComponentLifeStyle(生命周期);

您确定缓存post数据的不是
ModelState
?因为这就是HTMLHelper(
Html.TextArea()
在本例中)从中获取值的地方

尝试添加
ModelState.Clear()
保存操作中重定向之前

或者,如果您只想清除该字段,而不是整个ModelState,则:
ModelState[“Body”].Value=newvalueProviderResult(“,”,CultureInfo.CurrentCulture)

忘记数据访问代码。这总是一篇新文章。在我开始向数据库写入数据之前,这个问题就在这个方法的最顶端。我找到了问题的根源,但没有找到解决方案:(有关更多详细信息,请查看编辑。在编写控制器工厂时,每个请求都返回单例控制器而不是新实例是一个常见错误。最近发布的MVC 2 Preview 2检查此情况并显示一个描述解决方案的错误,因此未来的开发人员不应遇到同样的问题。经过数小时的尝试后为了弄清楚什么是神奇的缓存,你终于给出了答案。谢谢!
        // This only initialized the Castle IOC container
        DependencyRegistrat.Init();

        DependencyRegistrat.GetDefaultContainer().RegisterAll<IController>(typeof(HomeController).Assembly, ComponentLifecycle.Transient);

        ControllerBuilder.Current.SetControllerFactory(new MyControllerFactory(DependencyRegistrat.GetDefaultContainer()));
    protected override IController GetControllerInstance(Type controllerType)
    {
        Check.IsNotNull(controllerType, "The given controller type was null, but must be provided");

        return (IController) _Container.Resolve(controllerType);
    }

    public override void ReleaseController(IController controller) 
    {
        var disposable = controller as IDisposable;

        if (disposable != null) disposable.Dispose();

        _Container.Release(controller);
    }
}
_Container.AddComponentLifeStyle(typeof(K).FullName.ToLower(), typeof(K), (lifecycle);
_Container.AddComponentLifeStyle<I, K>(lifecycle);