Edited
I have an ASP.NET Core 2.1 website which I've scaffolded all of its Identity items. The scaffolding process created a layout file in this location:
/Areas/Identity/Pages/Account/Manage/_Layout.cshtml
As I wanted to use the layout globally, I have moved the layout file (with cut-paste) to this new location:
/Views/Shared/AdminLayout/_Layout.cshtml
Then created a _ViewStart.cshtml
file in the first location to use the layout in the 2nd location. The content of _ViewStart
file is this:
@{
Layout = "/Views/Shared/AdminLayout/_Layout.cshtml";
ViewData["ThisOneWorks"] = "some value";
}
Now the problem is, ViewData
s that I set from scaffolded pages (e.g. SetPassword.cshtml
, ExtenalLogins.cshtml
, ...) are not working in the layout file. For example ViewData["Title"]
is always empty, but the ViewData
that I've set in the _ViewStart
is working.
The question is, How can I use ViewData
from scaffolded identity files when I'm using a layout from the shared view folder?
Edit 1:
It seems the problem is with this line:
ViewData["ThisOneWorks"] = "some value";
When I remove it from the _ViewStart
, all other ViewData
s work correctly, but why?