2012-08-02 77 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