views:

1939

answers:

4
  1. I was following Steven Sanderson's 'Pro ASP.NET MVC Framework' book.
  2. On page 132, in accordance with the author's recommendation, I downloaded the ASP.NET MVC Futures assembly, and added it to my MVC project.
  3. Then, without encouragement from the author, I downloaded, installed, and incorporated the ASP.NET MVC2 Preview 1 dlls into my project.
  4. Now, I can no longer load the website.
    1. That is, when I hit F5 in Visual Studio, I get this error.

In retrospect, I think it was a really bad idea to assume that ASP.NET MVC2 Preview 1 would only be additive; but I'd like other people to weigh in.

Has anyone noticed any breaking changes in ASP.NET MVC 2 Preview 1?

Also - Has anyone noticed any changes that impact Castle Windsor?

Also, please let me know if I should be mindful of IIS6 vs. IIS7 ramifications.

+2  A: 

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

Jim G.
+3  A: 

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

dwhite
+2  A: 

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

Jason Stonebraker
+1  A: 

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.

David Liddle