Reputation: 9800
The image of a login page (clickable image):
Is it seems (though the debug viewer), the ViewEngines
are both (razor+webforms, im using the first) there, in the ViewEngines
collection, and them both can find the views (manually) and display them, also tried manually.
So why is that they cannot do it on their own? This is simply an action method, nothing more:
public ViewResult Login()
{
return View();
}
I have overridden the OnResultExecuting
method:
protected override void OnResultExecuting(ResultExecutingContext filterContext)
{
if (filterContext.Result is ViewResult)
{
if (((ViewResult)filterContext.Result).ViewEngineCollection.Count == 0)
{
((ViewResult)filterContext.Result).ViewEngineCollection.Add(new RazorViewEngine());
}
}
base.OnResultExecuting(filterContext);
}
And it turned out that every time and every view I do now need to add new IViewEngine
to a ViewResult
. Now why is that so? Even if the ViewEngines.Engines
collection is not empty?
The ViewEngineCollection
stopped being empty at some point of idling.
Upvotes: 2
Views: 850
Reputation: 9800
The ViewEngineCollection
stopped being empty at some point of idling.
This only might refer to some ASP.NET caching of old assemblies which was not for some reason updated by the new ones. This happens from time to time, and I have to clear the cache in order for some new code to work.
Upvotes: 0
Reputation: 11
Do you have a master page defined?
If you have a _ViewStart.chstml file in the root of your solution then it is possible the engine is trying to load a master page to combine with your view.
To skip the master page tell your view to not use a master page. Add the following to the View
@{
Layout = null;
}
or make sure that the master page referenced in the _viewStart.cshtml file exists.
Upvotes: 1
Reputation: 19457
You may not have a correct ViewEngines
configured (or none).
Try adding to view engines manually to identify if there is a configuration error somewhere.
Add something like this to Application_Start()
method of Global.asax
.
protected void Application_Start()
{
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
// Other code
}
This should initialise the Razor view engine, and if as a result mvc starts searching locations, you have somehow turned off razor in the configuration.
Upvotes: 0