Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6737033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:12:02+00:00 2026-05-26T11:12:02+00:00

I have written a test ViewEngine which responds to requests with a view name

  • 0

I have written a test ViewEngine which responds to requests with a view name of “About”, and added the following to the Application_Start method in Global.asax.

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
ViewEngines.Engines.Add(new MyViewEngine());

The FindView method of MyViewEngine is as follows:

if (viewName == "About")
    return new ViewEngineResult(new MyView(), this);
return new ViewEngineResult(new List<string>{"Some arbitrary search location"});

As the Home controller responds to the action About, I would have expected the RazorViewEngine to handle a request for ~/Home/About (as it was added to the Engines collection first) but it’s not… MyViewEngine is handling calls to that URL instead.

Calls which result in views not named “About” are handled correctly by Razor.

Even if I reverse the order of the two Add statements above, I get the exact same behavior. If I comment out the code which registers my view engine, Razor does pick up ~/Home/About as I would expect.

Any ideas why MyViewEngine is creating views ahead of Razor when it shouldn’t be?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:12:03+00:00Added an answer on May 26, 2026 at 11:12 am

    ASP.NET MVC asks the registered ViewEngines in their registration order as expected. However there is one catch. It’s in the ViewEngineCollection FindView method:

    public virtual ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName)
    

    This method iterates through the available ViewEngines asking for a view but it does it twice. Once with calling the FindView method with useCache=true and if none of the ViewEngines provided a result it iterates over them another time with useCache=false.
    So in your case when it asks the RazorViewEngine with useCache=true it does not return a view because there is no chached one. But your view engine will always provide View. So you need to handle the useCache=true case in your implementation:

    public ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
    {
        if (useCache)
            return new ViewEngineResult(new List<string> { "Not in cache" });
    
        if (viewName == "About")
            return new ViewEngineResult(new MyView(), this);
        return new ViewEngineResult(new List<string> { "Some arbitrary search location" });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following Midje test: (fact (followers-minus-friends ...name...) => [Dude] (provided (idset
I have written the following simple test in trying to learn Castle Windsor's Fluent
I have written a test method for a web service in VS2008, using visual
I have written a small test program in which I try to use the
I have written some Objective-C test cases. A typical looks the following: - (void)
I'm new to unit testing and have written the following test: /** * @expectedException
I have written a small unit test for my django view .My project structure
I have written few test scripts using JUnit 4 and Selenium. I have added
I have written a test, which I know is wrong. I know that this
I have written a test case which shows the error from unittest import *

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.