2016-10-10 54 views
0

我想用我剛下載的圖標替換這三個字段編輯/細節/刪除。這些圖標大小爲512x512,這會是一個問題嗎?我可以在代碼中調整它們的大小(如何),或者我應該使用某個程序調整它們的大小。 我一直在尋找網絡,我發現了一些非常長的C#代碼片段,但我不知道在哪裏放置它以便用圖標替換那些屬性的文本。MVC替換編輯/詳細信息/刪除圖標

這裏是我的HTML:

@using PagedList.Mvc; 
@model PagedList.IPagedList<Rating_System.Models.tblTeacher> 
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" /> 
@{ 
    ViewBag.Title = "Teachers List"; 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
} 

<h2>Teachers</h2>  
<p> 
    @Html.ActionLink("Add new", "Create") 
</p> 
@using (Html.BeginForm("Index", "Teachers", FormMethod.Get)) 
{ 

<p> 
    Търсене: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string) 
    <input type="submit" value="Search" /> 
</p> 
} 
<table class="table">  
    <tr> 
     <th>     
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.First().FirstName)  
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.First().SecondName) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.First().Title) 
     </th>      
     <th></th> 
    </tr> 

    @foreach (var item in Model) 
    { 
     <tr> 
      <td> 
       <img src="@Url.Action("GetImage", "Teachers", new {item.ID})" width="45" height="45" /> 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.FirstName) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.SecondName) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.Title) 
      </td>    
      <td> 
       @Html.ActionLink("Редактирай", "Edit", new { id = item.ID }) | 
       @Html.ActionLink("Детайли", "Details", new { id = item.ID }) | 
       @Html.ActionLink("Изтрий", "Delete", new { id = item.ID }) 
      </td> 
     </tr> 
    }  
</table> 

@Html.PagedListPager(Model, page => Url.Action("Index", new { page, pageSize = Model.PageSize })) 
Results @Model.FirstItemOnPage - @Model.LastItemOnPage от общо @Model.TotalItemCount Teachers 
+0

用''更改'@ Html.ActionLink(「Редактирай」,「Edit」,new {id = item.ID})'或者創建一個自定義HTML助手來渲染圖像。應通過設置寬度和高度屬性來調整所有提供的圖像的大小。 –

回答

0

嘗試使用此代碼

<a href="@Url.Action("ActionName", "ControllerName", new { id = item.ID })"> 
    <img src="@Url.Content("~/Content/imgname.jpg")" /> 
</a> 
+0

它按照我的意願工作! – Georgi93

0

如果你想使用一個圖標(圖像)使用下面的代碼:

@Html.ActionLink("Редактирай", "Edit", new { id = item.ID }, new { @class="class" }) 

然後寫你的CSS樣式包括背景圖像

a.class 
{ 
background: url(../Images/image.gif) no-repeat top left; 
width: 50px; 
height: 50px; 
display: block; 
text-indent: -9999px; /* hides the link text */ 
} 

但是,我會建議使用自舉glyphicons例如

<a href="@Url.Action("Action", "Controller")" class="btn btn-info"> 
Your link text 
<span class="glyphicon glyphicon-time" aria-hidden="true"></span> 
</a> 

或者

<span class="glyphicon glyphicon-ok" style="cursor:pointer" onclick="JavascriptFunction()"></span> 

而且在Javascript

function JavascriptFunction() { 
window.location.href = encodeURI("/Controller/Action/"); 
} 

你可以通過JavaScript函數傳遞ID

相關問題