ASP.NET MVC View Engine Resolution Sequence

Posted by intangible02 on Stack Overflow See other posts from Stack Overflow or by intangible02
Published on 2010-03-08T03:46:09Z Indexed on 2010/03/08 3:51 UTC
Read the original article Hit count: 405

Filed under:
|
|

I created a simple ASP.NET MVC version 1.0 application. I have a ProductController which has one action Index. In the view, I created a corresponding Index.aspx under Product subfolder.

Then I referenced the Spark dll and created Index.spark under the same Product view folder. The Application_Start looks like

    protected void Application_Start()
    {
        RegisterRoutes(RouteTable.Routes);

        ViewEngines.Engines.Clear();
        ViewEngines.Engines.Add(new Spark.Web.Mvc.SparkViewFactory());

        ViewEngines.Engines.Add(new WebFormViewEngine());

    }

My expectation is that since the Spark engine registers before default WebFormViewEngine, when browse the Index action in Product controller, the Spark engine should be used, and WebFormViewEngine should be used for all other urls.

However, the test shows that the Index action for Product controller also uses the WebFormViewEngine.

If I comment out the registration of WebFormViewEnginer (the last line in the code), I can see that the Index action is rendered by Spark engine and the rest urls generates an error (since the defualt engine is gone), it proves that all my Spark code is correct.

Now my question is how the view engine is resolved? Why the registration sequence does not take effect?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about view-engine