Results 1 to 3 of 3

Thread: Blazor Page Navigation and Parameter Passing - is there a best practice?

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,484

    Blazor Page Navigation and Parameter Passing - is there a best practice?

    I don't know if there's a right answer to this or if it's a matter of preference.

    I need to have conditonal HTML on a page. It is going to decide what kind of DevExpress Blazor controls to render. I am display communications systems. Some of our customers have radios so I'll display TX and RX frequencies. Others have consoles where I'll display the console type. So I want to have conditional logic determining what the system type is and create the appropriate controls.

    My question - is it "better" to pass in the system type from the previous page (I am already passing in the SystemDataControl #), or have the current page that will have the conditional logic discover what the system type is? Either way it's a database call but IDK if it's better to come into the page having all I need (two arguments) or give the page the minimum one argument and have it get the rest.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,484

    Re: Blazor Page Navigation and Parameter Passing - is there a best practice?

    So I thought I would try it one way to at least test my conditional code rendering. So I am trying to pass two parameters instead of one.
    Passing one worked, it looked like this minus what I put in bold on the last line. This file is NavMenu.razor.
    Code:
    <DxTreeView AllowSelectNodes="true" CssClass="app-sidebar">
        <Nodes>
            <DxTreeViewNode NavigateUrl="./" Text="Overview" CssClass="@rootNodeCssClass"></DxTreeViewNode>
                <DxTreeViewNode NavigateUrl="grid" Text="Grid" CssClass="@rootNodeCssClass"></DxTreeViewNode>
                <DxTreeViewNode NavigateUrl="choosecustomer3" Text="Choose Customer Grid" CssClass="@rootNodeCssClass"></DxTreeViewNode>
                <DxTreeViewNode NavigateUrl="systemdatadetails/3187,radio" Text="System Data Details" CssClass="@rootNodeCssClass"></DxTreeViewNode>
            </Nodes>
    </DxTreeView>
    But now there's a second parameter. I am trying to tell SystemDataDetails.razor to render the "radio" code. I get a very unclear "object reference not set to an instance" in _Host.cshtml with the addition of the "radio" parameter.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  3. #3

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,484

    Re: Blazor Page Navigation and Parameter Passing - is there a best practice?

    I don't need an answer anymore. I missed the most obvious and easy way to do this! When I come into the page that has conditional rendering, I get the row from the database that is the system. I can just ask what the "Console" is at that point.

    Code:
        protected override async Task OnInitializedAsync()
        {
            customerSystem = await _db.GetSystemBySDC(Convert.ToInt32(sdcvalue2));
    
            // 4 is radio, 2 is BDA
            if (customerSystem.Console == 4)
            {
                systemType = "Radio";
    
            radioSystemsData = new()
                {
                    DataDescription = customerSystem.DataDescription,
                    OwnerID = customerSystem.OwnerID,
                    SystemDataControl = customerSystem.SystemDataControl,
                    TXPL = customerSystem.TXPL,
                    TXFrequency = customerSystem.TXFrequency,
                    TXPLType = customerSystem.TXPLType
                };
            }
            else
            {
                systemType = "BDA";
    
    
            bdaSystemsData = new()
                {
                    DataDescription = customerSystem.DataDescription,
                    OwnerID = customerSystem.OwnerID,
                    SystemDataControl = customerSystem.SystemDataControl,
                };
            }
        }
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width