I tried to create a ViewComponent and try to use ViewData from it.
The ViewComponents are using different ViewContext from the page that executed it. This way I can't reach or set ViewData, that can be later passed to layout of the page.
I managed to reach the data of the parent with an ugly solution, while I kept trying:
(Component as IViewContextAware)?.Contextualize(ViewContext);
This way the ViewComponent could reach data from the page that invoked it, but the other way of the data cannot be made, because of the new context.
You could ask why I need ViewData in ViewComponent.
I am creating a "lot" (I hope it will be a lot) of libraries to make it easier to create a CMS system with ASP.NET Core. The only reference in my code is the MVC and EF, and I try to keep it for later. This way any project using MVC needs some CMS functionality, that can be inserted in no time without affecting the structure of the original project (only some entities in EF).
I needed a way to show views if I get a contentId.
I would like to use the higher abstraction levels of the framework as changing less frequently.
Pages with rewrite middleware was my first solution but those can be reached with the original URL too.
ViewComponent seemed the best solution, but I couldn't set the ViewData.
If there's any other options that with I can solve this problem please tell me.
MVC and Razor Pages: https://github.com/aspnet/Mvc
I tried to create a
ViewComponent
and try to useViewData
from it.The ViewComponents are using different
ViewContext
from the page that executed it. This way I can't reach or setViewData
, that can be later passed to layout of the page.I managed to reach the data of the parent with an ugly solution, while I kept trying:
This way the
ViewComponent
could reach data from the page that invoked it, but the other way of the data cannot be made, because of the new context.You could ask why I need ViewData in ViewComponent.
I am creating a "lot" (I hope it will be a lot) of libraries to make it easier to create a CMS system with ASP.NET Core. The only reference in my code is the MVC and EF, and I try to keep it for later. This way any project using MVC needs some CMS functionality, that can be inserted in no time without affecting the structure of the original project (only some entities in EF).
I needed a way to show views if I get a contentId. I would like to use the higher abstraction levels of the framework as changing less frequently.
ViewData
.If there's any other options that with I can solve this problem please tell me.