Note that there are some explanatory texts on larger screens.

plurals
  1. POAsp.Net MVC Beta: Previous RouteData overrides current RouteData?
    text
    copied!<p>I have something similar to the following method: </p> <pre><code> public ActionResult Details(int id) { var viewData = new DetailsViewData { Booth = BoothRepository.Find(id), Category = ItemType.HotBuy }; return View(viewData); } </code></pre> <p>and the following Route:</p> <pre><code>routes.MapRoute("shows","shows/{controller}/{action}/{id}", new {id = 0}); </code></pre> <p>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 <code>ModelState</code> contains the last-use id value. This causes the <code>ActionInvoker</code> to use it in the method's parameter instead of the <code>Route</code> value.</p> <p>So if I call the action twice on two different entities the results are such:</p> <pre><code>www.mysite.com/shows/Booth/Details/1 =&gt; Details(1) www.mysite.com/shows/Booth/Details/2 =&gt; Details(1) //from ModelState["id"] </code></pre> <p>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. </p> <p>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.</p> <p>EDIT: 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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload