How to send a value through href?

47 Views Asked by At

I am trying to pass a column value through an href link, but instead of receiving the value, I am getting the column name.

<SfGrid DataSource="@List" AllowSorting="true" AllowPaging="true" PageSize="10">
        <GridColumns>
            <GridColumn Field=@nameof(tbl_View.Number) HeaderText="Number" TextAlign="TextAlign.Left" Width="100"></GridColumn>
            <GridColumn Field=@nameof(tbl_View.Name) HeaderText="Name" TextAlign="TextAlign.Left" Width="200"></GridColumn>
            <GridColumn Field=@nameof(tbl_View.PhysicalAddress) HeaderText="Address" TextAlign="TextAlign.Left" Width="200"></GridColumn>
            <GridColumn Field=@nameof(tbl_View.PhysicalCity) HeaderText="City" TextAlign="TextAlign.Left" Width="150"></GridColumn>
            <GridColumn Field=@nameof(tbl_View.PhysicalState) HeaderText="State" TextAlign="TextAlign.Left" Width="100"></GridColumn>
            <GridColumn Field=@nameof(tbl_View.PhysicalZip) HeaderText="Zip" TextAlign="TextAlign.Left" Width="100"></GridColumn>
            <GridColumn Field=@nameof(tbl_View.Group_Name) HeaderText="Group" TextAlign="TextAlign.Left" Width="150"></GridColumn>
            <GridColumn Field=@nameof(tbl_View.Number) HeaderText="Number" TextAlign="TextAlign.Left" Width="150" Type="ColumnType.String">
                <Template>
                    <a href="Edit/tbl_View.Number">Edit</a>
                </Template>
            </GridColumn>
            <GridColumn HeaderText="">
                <Template>
                    <a href="MasterPolicySetup/tbl_View.Number">Master Policy</a>
                </Template>
            </GridColumn>
        </GridColumns>
    </SfGrid>

`

In above code, I am trying to pass tbl_View.Number to my Edit page, but there I am receiving value as "tbl_View.Number"

Can anyone help me with passing actual value?

1

There are 1 best solutions below

4
On

You need to do some string interpolation and formatting:

<a href="@($"MasterPolicySetup/{tbl_View.Number}")">Master Policy</a>

The string interpolation and formatting is $"MasterPolicySetup/{tbl_View.Number}". It's wrapped in a @(...) so Razor inteprets it as C# code. And Html expects href="" so iut'a quoted.

See: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated