How to pass and get the value correctly?

2 settimane tempo fa
Hi!
How to pass and get the value correctly?
@await Component.InvokeAsync(typeof(HeaderLinksViewComponent), new { val = 1})

value output in
@{
    var p = this.ViewData.ContainsKey("val");}
@p

I have @p outputting False. Why? What am I doing wrong?
Thanks.
2 settimane tempo fa
gnikitsin wrote:

@await Component.InvokeAsync(typeof(HeaderLinksViewComponent), new { val = 1})


you can pass like this
  @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.ProductDetailsOverviewTop, additionalData = Model })

you can give null to the widgetzone name and additionalData = 1

Inside controller, you can set value like this
 ViewBag.RefreshPage = true;

and use like this at view page
@if (ViewBag.RefreshPage == true)
{
}

//Rashed
2 settimane tempo fa
nopStation wrote:

@await Component.InvokeAsync(typeof(HeaderLinksViewComponent), new { val = 1})


you can pass like this
  @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.ProductDetailsOverviewTop, additionalData = Model })

you can give null to the widgetzone name and additionalData = 1

Inside controller, you can set value like this
 ViewBag.RefreshPage = true;

and use like this at view page
@if (ViewBag.RefreshPage == true)
{
}

//Rashed


Is there any way without using the controller source code? I just need to pass any value from one representation to another.
2 settimane tempo fa
Just use ViewData directly:
ViewData["val"] = 1;
@await Component.InvokeAsync(typeof(HeaderLinksViewComponent))
2 settimane tempo fa
New York wrote:
Just use ViewData directly:
ViewData["val"] = 1;
@await Component.InvokeAsync(typeof(HeaderLinksViewComponent))

In the introduction. _Header.cshtml
@await Component.InvokeAsync(typeof(HeaderLinksViewComponent))

I call it twice. The first time with the parameter "h-1", second with the parameter"h-2". In the introduction._Default.cshtml (HeaderLinks) I need to do something like this

@{
    var p = this.ViewData["val"];
}
@if (p == "h-1")
{
   //code 1
}
@if (p == "h-2")
{
   //code 2
}

1 settimana tempo fa
Yes, you can do that.  Do you have a question?