Another change is when dealing with form lists from your ViewModel.
For example in MVC 1.0 if you had a list of objects IList< MyObject > displayed in your View
<% for (int i = 0; i < Model.Length; i++) { %>
<%= Html.TextBox("MyObject[" + i + "].FirstName") %>
<%= Html.TextBox("MyObject[" + i + "].LastName") %>
<% } %>
The input boxes would be rendered as
<input id="MyObject[0]_FirstName" name="MyObject[0].FirstName" type="text" value="" />
Note: id = MyObject[0]_FirstName and name = MyObject[0].FirstName
However, in MVC 2.0 they are rendered as
<input id="MyObject_0__FirstName" name="MyObject[0].FirstName" type="text" value="" />
Note: id = MyObject_[0]__FirstName and name = MyObject[0].FirstName
This broke some jquery I was using to manipulate my table data. Notice the single and double underscores in the id.
If you are working from Steven Sanderson's book, Pro ASP.Net MVC Framework, then you'll need to make a change to the WindsorControllerFactory class to work with the interface exposed by the DefaultControllerFactory. This class was updated in the MVC 2 Preview 2. Who knows what the final release will hold.
Change:
protected override IController GetControllerInstance(Type controllerType)
To:
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
I've also found it necessary to ensure that the MVC 2 Preview 2 framework hasn't passed in a non-controller class (it was unexpectedly passing in favicon.ico as the controllerType). So the updated GetControllerInstance method looks like this:
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
//Debug.Print("Controller: {0}, Action: {1}", requestContext.RouteData.Values["Controller"], requestContext.RouteData.Values["Action"]);
if (controllerType == null)
{
//Debug.Print("Is IController: {0}", (controllerType is IController));
//Debug.Print("Is null: {0}", (controllerType == null));
return null;
}
else
{
return (IController)container.Resolve(controllerType);
}
}
I left the Debug code in there in case you're interested in seeing why you're getting a "Value cannot be null" error in the WindsorControllerFactory.
After making this change, Windsor began working for me. Hopefully, this will help.
Cheers, Jason
I had problems with Castle and MVC2 in VS 2010 Beta 2.
I was able to get Castle working with this code for the GetControllerInstance. The problem was that all requests were coming into this (like css files), so just returning null for those seems to work.
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (controllerType == null) { return null; }
return (IController)_container.Resolve(controllerType);
}
-Damien
From ScottGu's blog (unanswered as of this moment):
Tuesday, August 18, 2009 1:36 PM by Patrick Cooper Scott,
Love the direction of MVC. One question, in MVC 2, you've changed the signature for GetControllerInstance from just System.Type to System.Web.Routing.RequestContext and System.Type. Is intentional and permanent? It's causing problems with Castle that I'm not sure yet how to handle.
Thanks!
Patrick