将网址添加到html.grid列 [英] adding URL to html.grid column
问题描述
!{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成为指向同一网址的超链接.
In the above grid I have a CurrentUrl. This URL is pointing to a website. I need to make the Current URL a hyperlink to the same Url.
在我添加的页面上
use namespace="MvcContrib.UI.Grid.ActionSyntax"
有一种Action语法可以添加超链接.我认为代码看起来像
There is an Action syntax to add hyperlink. I think the code will look something like
column.For(x => x.CurrentUrl).Named("Current Url").Action(href)
column.For(x => x.CurrentUrl).Named("Current Url").Action(href)
需要有关将超链接添加到以上列的语法的帮助.
Need help with the syntax to add hyperlink to the above column.
推荐答案
除非您要使用ActionSyntax,否则可以独立创建Html.ActionLink,前提是您知道href即将包含什么值.
Unless you want to use ActionSyntax, you can create the Html.ActionLink independently assuming you know what values are coming in for your href.
如果href是实际的URL(http://www.example.com),则标准HTML可与Spark配合使用:
If href is an actual URL (http://www.example.com), standard HTML works with Spark:
column.For(c =>
string.Format("<a href='{0}'>{1}</a>", x.Grade, "Previous Url"))
.Named("Column Header")
.DoNotEncode();
如果您要基于设置的操作名称和ID(例如定向到编辑页面)来构建URL:
If you're building your URL based on a set Action name and Id (such as directing to an edit page):
column.For(c =>
Html.ActionLink("Previous Url",
"Action_Method_Name",
new { controller = "DifferentController", //optional
id = c.YourIdColumnIfRequired //optional
})
.Named("Column Header")
.DoNotEncode();
这篇关于将网址添加到html.grid列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!