T4MVC returning method name as view

Apr 13, 2012 at 9:58 PM

I have a form that works fine on submit from a code standpoint. If the model state is not valid it drops down into an else statement that returns the view and its current model.

Here is the Method:

        public virtual ActionResult requestQuoteSubmit(RequestQuoteFormModel requestQuote)

The name of the view is requestquote and it is contained in the home controller. Here is the view return statement:

return View(MVC.Home.requestquote().AddRouteValues(model));


Here is the error:

The view 'requestQuoteSubmit' or its master was not found or no view engine supports the searched locations. The following locations were searched:

I'm at a complete loss as to why it's taking the method and trying to return it as the view. Thoughts on this? Thanks.


Apr 13, 2012 at 11:38 PM

I'm a bit confused here: is your action method called requestQuoteSubmit() or requestquote()? You show the first method, but call the second name.

Apr 14, 2012 at 1:03 AM

The method for my form is called requestQuoteSubmit(). The view that I return (which contains the form) is called requestquote and it is part of the Home folder in the views and uses the Home controller. I instantiate a new RequestQuoteFormModel called model. If they model is not valid, I return the requestquote view along with the model.

return View(MVC.Home.requestquote().AddRouteValues(model));

This should return the requestquote view, yet my error message is telling me that requestQuoteSubmit is missing. So basically it appears that this is taking the form method and trying to return it as a view. Is my syntax wrong? I wasn't quite sure how to pass back a model with a view so I went with AddRouteValues(model) since that seemed to work. Does that make it a little clearer?

Apr 14, 2012 at 1:34 AM

Something here doesn't quite make sense. If you're able to write MVC.Home.requestquote(), then there must be a controller action named 'requestquote'. Also, what you pass to the View() method needs to be a view reference (e.g. return View(Views.requestquote)), not an action reference.

To clarify what you're trying to do, could you write it in the standard non-T4MVC way? From there I can help figure out the T4MVC equivalent.

Apr 14, 2012 at 2:20 AM

Ah, ok I see what you're saying. The formController is what handles all of my forms so when someone hits submit on a form it goes to a method located in the form controller. The view itself is actually located in another controller, in this case the home controller. The reason I can't do a View(Views.requestquote) is because the formController doesn't have that view. That's why I ended up doing the full reference by going MVC.Home.requestquote. If I were doing it the normal way it would look like this:

return View("../Home/requestquote", model);

I wasn't able to find something similar in the documentation so I'm guessing there's a strong possibility I'm doing something wrong syntactically here.

On a side note I really like what you've created here. Strongly typing everything makes it so much nicer. Thanks.

Apr 14, 2012 at 5:06 AM

Ah, I think I understand now. All you should need is:

    return View(MVC.Home.Views.requestquote, model);

Apr 14, 2012 at 6:07 AM
Edited Apr 14, 2012 at 6:08 AM

Ah, that seems to work! Thanks.