如何通过 href 发送数值?

huangapple go评论64阅读模式
英文:

How to send a value through href?

问题

<a href="Edit/@item.Number">Edit</a>
英文:

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

得分: 1

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

英文:

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

huangapple
  • 本文由 发表于 2023年3月21日 03:12:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75794384.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定