英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论