Usuário com melhor resposta
Usar imagens em substituicão aos textos nos links

Pergunta
-
O razor, por padrão nos entrega uma tela com texto para ser usado como links.
@Html.ActionLink("Edit", "Edit", new { id=item.AlbumId }) | @Html.ActionLink("Details", "Details", new { id=item.AlbumId }) | @Html.ActionLink("Delete", "Delete", new { id=item.AlbumId })
Encontrei um post do Ivan Paulovich que fala como substituir o texto por uma imagem, citando o exemplo de "Delete" por lixeira.png.
Substitua isso: @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
Por algo assim: <a href="@Html.Action("Delete", "delete", new { /* id=item.PrimaryKey */ })"> <img src="/Content/btnlixeira.jpg" /></a> abraços!
Tentei aplicar e deu um pau danado. Mesmo quando só testei com um link, removendo os dois outros, continuou longe de funcionar.
@Html.ActionLink("Edit", "Edit", new { id=item.AlbumId }) | @Html.ActionLink("Details", "Details", new { id=item.AlbumId }) | <a href="@Html.Action("Delete", "Delete", new {id=item.AlbumId})">
<img src="~/Content/Images/lixeira.png" /></a>
Alguém pode me dar uma força?
Carlos Perez.
Respostas
-
E porque não assim :
@Html.ActionLink("Edit", "Edit", new { id=item.AlbumId }) | @Html.ActionLink("Details", "Details", new { id=item.AlbumId }) | @{ var id = item.AlbumId; } <a href="/Delete/@id"> <img src="~/Content/Images/lixeira.png" /></a>
Davi Murilo Referência Principal : Jesus que ilumina minha mente.
Referência Profissonal : http://www.tidm.com.br- Marcado como Resposta Perez 2013 terça-feira, 23 de julho de 2013 17:06
-
Olá,
Você pode criar um helper para isso:
public static string ImageLink(this HtmlHelper htmlHelper, string imgSrc, string alt, string actionName, string controllerName, object routeValues, object htmlAttributes, object imgHtmlAttributes) { UrlHelper urlHelper = ((Controller)htmlHelper.ViewContext.Controller).Url; string imgtag = htmlHelper.Image(imgSrc, alt,imgHtmlAttributes); string url = urlHelper.Action(actionName, controllerName, routeValues); TagBuilder imglink = new TagBuilder("a"); imglink.MergeAttribute("href", url); imglink.InnerHtml =imgtag; imglink.MergeAttributes(new RouteValueDictionary(htmlAttributes), true); return imglink.ToString(); }
fonte
- Marcado como Resposta Perez 2013 terça-feira, 23 de julho de 2013 18:22
Todas as Respostas
-
E porque não assim :
@Html.ActionLink("Edit", "Edit", new { id=item.AlbumId }) | @Html.ActionLink("Details", "Details", new { id=item.AlbumId }) | @{ var id = item.AlbumId; } <a href="/Delete/@id"> <img src="~/Content/Images/lixeira.png" /></a>
Davi Murilo Referência Principal : Jesus que ilumina minha mente.
Referência Profissonal : http://www.tidm.com.br- Marcado como Resposta Perez 2013 terça-feira, 23 de julho de 2013 17:06
-
Olá,
Você pode criar um helper para isso:
public static string ImageLink(this HtmlHelper htmlHelper, string imgSrc, string alt, string actionName, string controllerName, object routeValues, object htmlAttributes, object imgHtmlAttributes) { UrlHelper urlHelper = ((Controller)htmlHelper.ViewContext.Controller).Url; string imgtag = htmlHelper.Image(imgSrc, alt,imgHtmlAttributes); string url = urlHelper.Action(actionName, controllerName, routeValues); TagBuilder imglink = new TagBuilder("a"); imglink.MergeAttribute("href", url); imglink.InnerHtml =imgtag; imglink.MergeAttributes(new RouteValueDictionary(htmlAttributes), true); return imglink.ToString(); }
fonte
- Marcado como Resposta Perez 2013 terça-feira, 23 de julho de 2013 18:22