I have two ViewComponent and i want use ViewData or other technic for share some data between and then use this data in main view, but this is not the way, and ViewData per ViewComponent is null when rich to if condition for both ViewComponent.
public class OneViewComponent : ViewComponent
{
public async Task<IViewComponentResult> InvokeAsync(Page page, Zone zone)
{
//some operation
string text = "one";
if(ViewData["data"] != null)
{
ViewData["data"] = ViewData["data"].ToString() + text;
}
else
{
ViewData["data"] = text;
}
return View();
}
}
public class TwoViewComponent : ViewComponent
{
public async Task<IViewComponentResult> InvokeAsync(Page page, Zone zone)
{
//some operation
string text = "two";
if(ViewData["data"] != null)
{
ViewData["data"] = ViewData["data"].ToString() + text;
}
else
{
ViewData["data"] = text;
}
return View();
}
}