【问题标题】:adding URL to html.grid column将 URL 添加到 html.grid 列
【发布时间】:2011-12-15 18:23:30
【问题描述】:
!{Html.Grid(Model.Results)
        .Columns(column =>
        {
          column.For(x => x.Title).Named("Article Name");
          column.For(x => x.Sites);
          column.For(x => x.PreviousPath).Named("Previous Path");
          column.For(x => x.CurrentPath).Named("Current Path");
          column.For(x => x.PreviousUrl).Named("Previous Url");
          column.For(x => x.CurrentUrl).Named("Current Url");
          column.For(x => x.LogDate).Named("Date");
        }
)
  .Empty("There are no R301s.")
}

在上面的网格中,我有一个 CurrentUrl。此 URL 指向一个网站。我需要将当前 URL 设为指向同一 URL 的超链接。

在我添加的页面上

use namespace="MvcContrib.UI.Grid.ActionSyntax"

有一个动作语法来添加超链接。我认为代码看起来像

column.For(x => x.CurrentUrl).Named("当前网址").Action(href)

需要有关将超链接添加到上列的语法方面的帮助。

【问题讨论】:

    标签: asp.net-mvc-2 spark-view-engine


    【解决方案1】:

    除非您想使用 ActionSyntax,否则您可以独立创建 Html.ActionLink,前提是您知道 href 输入的值。

    如果 href 是实际 URL (http://www.example.com),则标准 HTML 可与 Spark 一起使用:

    column.For(c => 
               string.Format("<a href='{0}'>{1}</a>", x.Grade, "Previous Url"))
                     .Named("Column Header")
                     .DoNotEncode();
    

    如果您基于设置的操作名称和 ID 构建 URL(例如指向编辑页面):

    column.For(c => 
               Html.ActionLink("Previous Url", 
                               "Action_Method_Name", 
                               new { controller = "DifferentController", //optional
                                     id = c.YourIdColumnIfRequired  //optional
                                   }) 
                   .Named("Column Header")
                   .DoNotEncode();
    

    【讨论】:

    • .net 4.5 中的 .DoNotEncode()(可能更早?)现在是 .Encode(false)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-02
    • 2015-01-25
    • 2012-03-31
    • 2015-02-08
    • 2011-11-10
    相关资源
    最近更新 更多