2012-08-02 76 views
0

我正在开发一个mvc.net网络应用程序。我用一个webgrid来显示我的数据库中的数据。将链接添加到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> 
+0

事实上,这些链接进行编辑,删除和显示有关每一行的细节。请帮助 – Kira 2012-08-02 09:58:54

+0

你只想要图像,甚至文字很酷? – Yasser 2012-08-02 10:04:13

+0

事实上,我已经找到了一种使用文本的方式,但我想要图像^^无论如何,谢谢你,yasser – Kira 2012-08-02 10:07:09

回答

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 [email protected]}, new { @class = "imgLink"}) 
+0

很酷,但我有问题在这里我得到了一个IEnuerable模型为我的看法,我不知道如何传递当前行的id作为一个参数的行动链接'@model IEnumerable ' – Kira 2012-08-02 10:16:21

+0

我想用'@ item.clientId'这样它应该工作 – Yasser 2012-08-02 10:24:58

+0

不幸的是,不幸的是 – Kira 2012-08-02 10:33:38