将链接添加到webgrid中

时间:2012-08-02 09:45:13

标签: asp.net asp.net-mvc asp.net-mvc-3 razor webgrid

我正在开发一个mvc .net web应用程序。我使用webgrid来显示数据库中的数据。

@{
    var grid = new WebGrid(Model, canPage:true , rowsPerPage :6);
    grid.Pager(WebGridPagerModes.NextPrevious);
      @grid.GetHtml(tableStyle: "webGrid", htmlAttributes: 
      new {id="datatable" },headerStyle: "Header", alternatingRowStyle : "alt",
      columns: grid.Columns(grid.Column("Nom"), grid.Column("Prenom"),     
      grid.Column("Email")));
}

我只想在每行添加3个操作链接。怎么做。这是我的动作链接(我使用图像而不是文本)

<a href="@Url.Action( "Details", new { id = item.id_client })">
    <img src="~/Images/details.png" alt =""/></a>
<a href="@Url.Action( "Edit", new { id = item.id_client })">
    <img src="~/Images/modifier.png" alt =""/></a>
<a href="@Url.Action( "Delete", new { id = item.id_client })">
    <img src="~/Images/supprimer.png" alt =""/></a>

1 个答案:

答案 0 :(得分:4)

Muliple从SO回答

<强> Method 1

<a href="@Url.Action("Edit", new { id=MyId })"><img src="@Url.Content("~/Content/Images/Image.bmp")", alt="Edit" /></a>

<强> Method 2

grid.Column(header: "Details",
            format: @<text><img src="@Url.Content("~/Content/Images/view-fullscreen.png")"
             style="cursor: pointer" onclick="openPopup('@item.EncryUserId')"                                                                        
             alt="View Detail" title="View Detail"/></text>) 

<强> Method 3

@Html.ActionLink("Update", "Update", @item.Price, new { @class = "imgLink"})

.imgLink
{
  background: url(YourImage.png) no-repeat;
}

明智地选择;)

Update

@Html.ActionLink("Update", "Update", new{@postID =@item.PostID}, new { @class = "imgLink"})