views:

75

answers:

1

Now that MVC 3 Preview 1 here, we can use Razor (.cshtml) view engine. If a view not found, I get this error:

The view 'a' or its master was not found. The following locations were searched:
~/Views/Home/a.aspx
~/Views/Home/a.ascx
~/Views/Shared/a.aspx
~/Views/Shared/a.ascx
~/Views/Home/a.cshtml
~/Views/Shared/a.cshtml

Would it be worth to remove the .aspx/.ascx lookup, if I don't plan to use them?

+8  A: 

I doubt you would gain any noticeable performance gain from that. It's merely a file check and if it's also cached by the engine there's hardly any performance improvement. I'd call it micro-optimization!

I guess if you know you won't be using WebForms, you could just remove it from the list of view engines, like so:

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new CshtmlViewEngine());

or this (same thing):

ViewEngines.Engines.RemoveAt(0); // I'm God and I know WebFormsViewEngine is first.

That way it won't check for aspx/ascx files.

Manticore
I would recomend the first option, since we (MVC team) are not currently comitting to any particular order of view engines in that collection.
marcind
@marcin: It's probably best to find the View Engines you don't want and manually remove them by locating their index and removing them. That way if MVC ever adds extra view engines (or other components register their own view engines) you won't be removing them.
Eilon
True, thought about that too, but as he only wanted to use Cshtml I didn't add it. Could look something like this: `ViewEngines.Engines.Remove(ViewEngines.Engines.OfType<WebFormViewEngine>().First());`Funny how many different ways you can write this!
Manticore