将超链接插入 WebGrid
我到处搜索,就在几周前,我看到很多网站都没有这方面的样本,但现在我却找不到它们了!
我有一个网络网格,对于某些列,我需要在行中插入超链接,例如:
<a href="someurl.cshtml?something=this&that=something" title="eh?">@rowValue</a>
有这方面的文档吗?我在 MSDN 上能找到的似乎都是非常基本的东西,而这似乎并不在那里。
谢谢!
I have searched high and low, and it was only a few weeks ago I saw heaps of sites that had little samples for this, but for the life of me can't find them now!
I have a webgrid, and for certain columns, I need to insert hyperlinks into the rows, like:
<a href="someurl.cshtml?something=this&that=something" title="eh?">@rowValue</a>
Are there any Docs for this? All I can seem to find on MSDN is very basic stuff, and this doesn't seem to be in there.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
format
参数将接受 HTML,只要您在其前面加上@
符号,并且该参数是自闭合的,或者包含在The
format
parameter will accept HTML, so long as you prefix it with the@
sign and it is self-closing, or wrapped in<text>
tags. It's a Razor Template, which is described by Phil Haack here and Andrew Nurse here.或者,您可以使用 @Html.ActionLink 的格式,例如
grid.Column(@Html.ActionLink(linkText: (string)@item.Customer.LastName + ", " + (string)@item.Customer.FirstName,
)
标题:“名称”,
可以排序:正确,
列名:“客户.姓氏”,
格式:@
动作名称:“详细信息”,
路线值:新{id=item.Id})
在代码片段中,“item”具有属性“Customer”,该属性具有属性 LastName 和 FirstName
Alternatively you can use the format with @Html.ActionLink, e.g.
grid.Column(
header: "Name",
canSort: true,
columnName: "Customer.LastName",
format: @<text>@Html.ActionLink(linkText: (string)@item.Customer.LastName + ", " + (string)@item.Customer.FirstName,
actionName: "Details",
routeValues: new { id = item.Id })
</text>)
In the code fragment "item" has property "Customer" that has properties LastName and FirstName