【问题标题】:Inserting Hyperlinks into the WebGrid将超链接插入 WebGrid
【发布时间】:2011-09-22 22:51:40
【问题描述】:

我到处搜索过,就在几周前,我还看到大量网站没有这方面的样本,但现在我一生都找不到它们!

我有一个 webgrid,对于某些列,我需要在行中插入超链接,例如:

<a href="someurl.cshtml?something=this&that=something" title="eh?">@rowValue</a>

有这方面的文档吗?我在 MSDN 上找到的似乎都是非常基本的东西,而这似乎并不存在。

谢谢!

【问题讨论】:

    标签: c# .net razor webmatrix webgrid


    【解决方案1】:
    grid.Column(
        format: @<a href="someurl.cshtml?something=this&that=something" title="eh?">@row.Value</a>
    )
    

    format 参数将接受 HTML,只要您在其前面加上 @ 符号并且它是自动关闭的,或者包裹在 &lt;text&gt; 标记中。这是一个 Razor 模板,由 Phil Haack hereAndrew Nurse here 描述。

    【讨论】:

    • 非常感谢@Mike,非常感谢。
    【解决方案2】:

    或者,您可以将格式与@Html.ActionLink 一起使用,例如

    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>)

    在代码片段中,“item”具有属性“Customer”,该属性具有 LastName 和 FirstName 属性

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-07
      • 2019-11-15
      • 2012-02-29
      • 1970-01-01
      • 1970-01-01
      • 2018-05-23
      • 2017-05-03
      • 2011-10-15
      相关资源
      最近更新 更多