如何使用 HTML.ActionLink 插入图像?
如何在 html.actionlink - asp.net mvc 中插入图像?
我这样做了,但它不起作用。
<a href="<%= Html.ActionLink("search", "Search", new { searchText = "txtSearch" }, null); %>">
<img alt="searchPage" style="vertical-align: middle;" height="17px"
src="../../Stylesheets/search.PNG" title="search" />
how to insert image in html.actionlink - asp.net mvc?
i did it so, but it doesnt works.
<a href="<%= Html.ActionLink("search", "Search", new { searchText = "txtSearch" }, null); %>">
<img alt="searchPage" style="vertical-align: middle;" height="17px"
src="../../Stylesheets/search.PNG" title="search" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您完全滥用了
ActionLink
帮助器。帮助器实际上生成整个标记。
在这种情况下,您真正想要使用的(除了您自己编写的助手之外)是:
You are completely misusing the
ActionLink
helper. The helper actually produces the whole<a href=".." ></a>
tag.What you really want to use in this case (apart from your own written helper) is this:
@Trimack 对于 MVC2 是 100% 正确的。如果人们正在寻找 MVC3 的等效项,这里就是......
@Trimack is 100% correct w/ MVC2. If people are searching for the MVC3 equivalent, here it is...
我已经为此解决方案创建了一个助手。所以你不能将图像包含到actionLink中。但是通过这个辅助类,您可以简单地添加带有图像的锚点以进行查看。
使用系统;
使用系统文本;
使用 System.Web.Mvc;
使用 System.Web.Mvc.Html;
使用 System.Web.Routing;
使用系统.Web;
使用系统.安全.策略;
祝你好运
i have create a helper for this solution. So u can't include image to actionLink. But with this helper class u can simply add anchor with image to view.
using System;
using System.Text;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
using System.Web;
using System.Security.Policy;
good luck
如果要显示多图像,可以在
View
中使用Html.ActionLink
属性,如下所示。在此示例中,我使用详细信息/编辑/删除图像作为操作列下的按钮。注意:在
Html.ActionLink
中输入Title
、Controller
和Action
名称,根据你的项目。如果您想使用空标题,只需输入“”即可。有关完整示例,您可以查看此处:如何使用cshtml 视图中的 WebGrid?
问候。
If you want to display multi images you can use
Html.ActionLink
property in yourView
as shown below. In this sample I use Detail/Edit/Delete images as a button under Action column.Note: Type
Title
,Controller
andAction
name inHtml.ActionLink
according to your project. If you want to use empty title simply type " " for them.For full example, you might look at here: How to use WebGrid in a cshtml view?
Regards.
您可以使用以下内容,而不是使用 @Html.ActionLink("linkname","action","controller") :
“images”是我存储图像的文件夹。
@Url.Content()
是为了知道路径。您可以将您的操作和该操作的控制器传递给@Url.Action()
。@Url.Action()
的工作方式与@Html.ActionLink()
类似。现在您的链接将被图像替换。Instead of using @Html.ActionLink("linkname","action","controller") you can use following:
"images" is my folder for storing the images.
@Url.Content()
is to know the path. You can pass your action and the controller for that action to@Url.Action()
.@Url.Action()
works similar to the@Html.ActionLink()
. Now your link will get replaced by the image.