I’m looking to create some hyperlinks in a Webgrid. I’d like to have the “User Name” column display it’s values as hyperlinks instead of text. Is it possible to incorporate the @Html.ActionLink function into the WebGrid below?
The columnName expects a string which corresponds to a property of the model that is being passed to the view. So the problem is how to get that into a link.
View:
@model IEnumerable<CIMsWebApp.Client.Group.Entities.IUser>
@{ var grid = new WebGrid(Model, canSort: true, canPage: true, defaultSort: "UserName", ajaxUpdateContainerId: "myUserGrid"); }
@grid.GetHtml(
tableStyle: "dataGrid",
headerStyle: "header",
alternatingRowStyle: "evenRow",
columns: grid.Columns
(
grid.Column(header: "User Name", columnName: "UserName", canSort: false),
grid.Column(header: "Role(s)", columnName: "Rolebuilder", canSort: false),
grid.Column(header: "Active", columnName: "ActiveInd", canSort: false),
grid.Column(header: "Action", format:
@<span><input type="button" class="edit-user" id="@item.PersonId" value="EDIT" />
</span>, canSort: false)
)
)
You could use the
formatparameter to provide any custom format you like for this cell (btw you already did this for the last column):