views:

347

answers:

1

I've got a base controller that takes a couple generics, nothing overly fancy.

public class SystemBaseController<TForm, TFormViewModel> : Controller
    where TForm : class, IForm
    where TFormViewModel : class, IViewModel

ok, no big deal. I have a method "CompleteForm" that takes in the viewModel, looks kinda like this ...

    public ActionResult CompleteForm(TFormViewModel viewModel)
    {
          //does some stuff

          return this.RedirectToAction(c => c.FormInfo(viewModel));
    }

Problem is, the controller that inherits this, like so

public class SalesFormController :  SystemBaseController<SalesForm, SalesViewModel>
{ }

I end up getting a error from MvcContrib - Controller name must end in 'Controller' at this point ...

    public RedirectToRouteResult(Expression<Action<T>> expression)
        : this(expression, expr => Microsoft.Web.Mvc.Internal.ExpressionHelper.GetRouteValuesFromExpression(expr)) {}

The expression that's passed in is correct (SystemBaseController blahblah) but I'm not sure why its 1.) saying there's no controller at the end, and 2.) if I pull out everything into the controller (out of the base), works just fine. Do I need to write or setup some kind of action filter of my own or what am I missing?

+1  A: 

OK, now that I see all this written out I think I see the problem.

MvcContrib figures out which controller to call by inferring from the lambda expression that you passed in, not the controller type. So when you say this.RedirectToAction(c => c.FormInfo(viewModel));, it looks at the lambda expression and infers that T is of type SystemBaseController<TForm, TFormViewModel>, not SalesFormController.

What you might have to do is change your base class to SystemBaseController<TForm, TFormViewModel, TController> so that you can say this.RedirectToAction<TController>(c => c.FormInfo(viewModel));. That might work.

Jon Kruger
I was thinking that ... not 100% sure how it'll wire up yet but I don't see why not, let me see what I can do
jeriley
tossed in an interface with the items in the base, then pass the controller in as another generic ... it picks it up finally. Also, strangely, I get a 404 on the redirect -- it's path is right though.
jeriley