Asp.Net MVC的测试:previous的RouteData覆盖当前的RouteData? [英] Asp.Net MVC Beta: Previous RouteData overrides current RouteData?

查看:130
本文介绍了Asp.Net MVC的测试:previous的RouteData覆盖当前的RouteData?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似下面的方法的内容:

I have something similar to the following method:

    public ActionResult Details(int id)
    {
        var viewData = new DetailsViewData
        {
            Booth = BoothRepository.Find(id),
            Category = ItemType.HotBuy
        };
        return View(viewData);
    }

和下面的路线:

routes.MapRoute("shows","shows/{controller}/{action}/{id}", new {id = 0});

一切工作得很好的测试版之前,当我有preVIEW 3.现在该方法将正确填写的ID,我第一次执行的操作。然而,第二次控制器的的ModelState 包含价值上次使用的ID。这将导致 ActionInvoker 在方法的参数,而不是路线值中使用它。

Everything worked fine before the Beta, when I had Preview 3. Now the method will fill the id correctly the first time I execute the action. However the second time the controller's ModelState contains the last-use id value. This causes the ActionInvoker to use it in the method's parameter instead of the Route value.

所以,如果我调用两次行动在两个不同实体的结果是这样的:

So if I call the action twice on two different entities the results are such:

www.mysite.com/shows/Booth/Details/1  => Details(1)
www.mysite.com/shows/Booth/Details/2  => Details(1)  //from ModelState["id"]

从我的快速扫描与反射似乎它首先绑定参数到的ModelState再到路线。但是,我从来没有发布从模型什么。至于我可以告诉ModelState中不应包含任何内容。

From my quick scan with Reflector it seems it first binds parameters to the ModelState then to Routes. However, I never even posted anything from the model. As far as I can tell the ModelState should not contain anything.

这在我的code某处是在Beta中的错误,可能是一个错误,或者是有一些设计的功能,我懵了吗?任何洞察ModelState中的性质和为什么发生这种情况是AP preciated。

Is this a bug in the Beta, possibly a bug somewhere in my code, or is there some design feature that I am ignorant of? Any insight into the nature of ModelState and why this happens is appreciated.

编辑:
 我发现这个问题实际上是这似乎是与DefaultValueProvider一个bug,如果你从存在的Asp.Net application.What发生的寿命IoC容器实例化控制器的症状是DefaultValueProvider使用第一个ControllerContext给控制器,直到控制器重新永远不会更新它。这将导致用于方法参数,而不是当前的RouteData旧的RouteData。

I discovered that this issue is actually a symptom of what appears to be a bug with the DefaultValueProvider if you instantiate a Controller from an IoC container that exists for the lifetime of the Asp.Net application.What happens is that the DefaultValueProvider uses the first ControllerContext given to the Controller and never updates it until the controller is recreated. This causes old RouteData to be used for method parameters instead of the current RouteData.

推荐答案

这是我很难告诉你期待什么发生,什么是从您的帖子发生。是否有可能有你的BoothRepository.Find方法的错误,这样它每次都返回同样的事情?

It's hard for me to tell what you expect to happen and what is happening from your post. Is it possible there's an error in your BoothRepository.Find method such that it returns the same thing every time?

ModelBinder的不应该影响这个方法,因为参数的操作方法是一种简单的类型,int类型。

ModelBinder should not be affecting this method because the parameter to the action method is a simple type, int.

都是这些请求的GET请求?如果仍然有问题,你可以尝试创建一个最简单的摄制可能并通过电子邮件发送到philha - 微软点com

Were both of these requests GET requests? If you still are having problems, can you try and create the simplest repro possible and email it to philha - microsoft dot com?

编辑:问题结束了,开发商正试图重新使用跨请求的valueprovider(通过让温莎城堡管理控制器的生命周期)。现在,有一个为重新使用控制器实例跨请求就像你使用的IHttpHandler具有IsReusable属性的支持。所以一般来说,跨请求重用控制器需要做对你的最终更多的工作。 :)

The problem ended up being that the developer was attempting to re-use the valueprovider across requests (by having Castle Windsor manage the lifecycle of Controllers). Right now, there's no support for re-using controller instances across requests like you would with IHttpHandler which has a IsReusable property. So in general, reusing controllers across requests requires doing a lot more work on your end. :)

这篇关于Asp.Net MVC的测试:previous的RouteData覆盖当前的RouteData?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆