问题
!{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.")
}
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.
On the page I have added
use namespace="MvcContrib.UI.Grid.ActionSyntax"
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)
Need help with the syntax to add hyperlink to the above column.
回答1:
Unless you want to use ActionSyntax, you can create the Html.ActionLink independently assuming you know what values are coming in for your href.
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();
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();
来源:https://stackoverflow.com/questions/7903726/adding-url-to-html-grid-column