Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

how to pass data between components mudblazor(or blazor)

$
0
0

I want to pass ActivatedValue.Value (which is my model's id) to another component.

@using ProtaTestTrack2.Helpers@using ProtaTestTrack2.Services@inject IDialogService DialogService<MudPaper Class="d-flex flex-column" Style="position: relative; padding: 16px;"><MudIconButton Icon="@Icons.Material.Filled.Add" Color="Color.Primary" Style="position: absolute; top: 10px; right: 50px;" OnClick="OpenDialog" /><MudIconButton Icon="@Icons.Material.Filled.Edit" Color="Color.Secondary" Style="position: absolute; top: 10px; right: 10px;" OnClick="EditFeature" /><MudTreeView Items="TreeItems" MultiSelection="false" SelectedValueChanged="FeatureChanged" @bind-ActivatedValue="ActivatedValue" @bind-SelectedValues="SelectedValues" Dense><ItemTemplate Context="item"><MudTreeViewItem @bind-Expanded="@item.IsExpanded" Items="@item.TreeItems" Value="@item"                            Icon="@item.Icon" Text="@item.Title" EndText="@item.Number?.ToString()" EndTextTypo="@Typo.caption"><BodyContent><MudText Style="justify-self: start;"><MudHighlighter Text="@context.Text" /></MudText></BodyContent></MudTreeViewItem></ItemTemplate></MudTreeView></MudPaper>@code {    private int myVar;    public int MyProperty    {        get { return myVar; }        set { myVar = value; }    }    [Inject] FeatureService featureService { get; set; }    private TreeItemData _ActivatedValue;    [Parameter]    public TreeItemData ActivatedValue    {        get { return _ActivatedValue; }        set        {            _ActivatedValue = value;            FeatureChanged.InvokeAsync(value);        }    }    [Parameter] public EventCallback<TreeItemData> FeatureChanged { get; set; }    [Parameter] public HashSet<TreeItemData> SelectedValues { get; set; } = new HashSet<TreeItemData>();    private HashSet<TreeItemData> TreeItems { get; set; } = new HashSet<TreeItemData>();    protected override async Task OnInitializedAsync()    {        await PopulateTree();    }    public async Task PopulateTree()    {        var features = await featureService.GetAllFeaturesAsync();        var treehelper = new Helpers.TreeviewHelper(features);        treehelper.BuildTree();        TreeItems = treehelper.TreeItems;        StateHasChanged();    }    private Task OpenDialog(MouseEventArgs e)    {        var options = new DialogOptions { CloseOnEscapeKey = true };        return DialogService.ShowAsync<FeatureDialog>("Feature", options);    }    private void EditFeature(MouseEventArgs e)    {        // Edit feature logic here    }}

this is my models component which is feature.

@using ProtaTestTrack2.Model@using ProtaTestTrack2.Services@inject FeatureService featureService<MudDialog><DialogContent><MudTextField T="string" Label="Name" @bind-Value="featureData.Name" /></DialogContent><DialogActions><MudButton OnClick="Cancel">Cancel</MudButton><MudButton Color="Color.Primary" OnClick="Submit">Ok</MudButton></DialogActions></MudDialog>@code {    public class FeatureData     {        public string Name { get; set; }        public string ParentFeatureID { get; set; }    }    [CascadingParameter]    private MudDialogInstance MudDialog { get; set; }    private FeatureData featureData = new FeatureData();    private async Task Submit()    {        var feature = MapFeatureData(featureData);        var createdFeature = await featureService.CreateFeatureAsync(feature);        MudDialog.Close(DialogResult.Ok(true));    }    private void Cancel() => MudDialog.Cancel();    private Feature MapFeatureData(FeatureData featureData)    {        return new Feature        {            Name = featureData.Name,            ParentFeatureID = featureData.ParentFeatureID        };    }}

and this is my dialog component for feature. I want to pass it to here because if the coming data is null that means i will create as parent but if data is not null i will map that data to parent featureId.

<FeatureDialog SelectedFeatureId="@_ActivatedValue?.Value" /> I tried something like that but it isn't working and also activated value might change constantly but I couldn't manage to handle.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>