在ASP的最新(RC1)版本中。NET MVC,我怎么得到Html。ActionLink渲染为按钮或图像而不是链接?
当前回答
延迟响应,但你可以保持简单,并应用CSS类htmlAttributes对象。
<%= Html.ActionLink("Button Name", "Index", null, new { @class="classname" }) %>
然后在样式表中创建一个类
a.classname
{
background: url(../Images/image.gif) no-repeat top left;
display: block;
width: 150px;
height: 150px;
text-indent: -9999px; /* hides the link text */
}
其他回答
你不能用Html.ActionLink这样做。你应该使用Url。RouteUrl并使用该URL来构造所需的元素。
延迟响应,但你可以保持简单,并应用CSS类htmlAttributes对象。
<%= Html.ActionLink("Button Name", "Index", null, new { @class="classname" }) %>
然后在样式表中创建一个类
a.classname
{
background: url(../Images/image.gif) no-repeat top left;
display: block;
width: 150px;
height: 150px;
text-indent: -9999px; /* hides the link text */
}
对于Material Design Lite和MVC:
<a class="mdl-navigation__link" href='@Url.Action("MyAction", "MyController")'>Link Name</a>
使用FORMACTION
<input type="submit" value="Delete" formaction="@Url.Action("Delete", new { id = Model.Id })" />
我喜欢像这样使用Url.Action()和Url.Content():
<a href='@Url.Action("MyAction", "MyController")'>
<img src='@Url.Content("~/Content/Images/MyLinkImage.png")' />
</a>
严格来说,Url。内容只在路径不是您问题答案的一部分时才需要。
感谢@BrianLegg指出这应该使用新的Razor视图语法。示例已相应更新。
推荐文章
- 从控制器内获得控制器和动作名称?
- _ViewStart的位置和方式。CSHTML布局文件链接?
- Visual Studio - Resx文件默认“内部”为“公共”
- ASP是什么?NET Identity的IUserSecurityStampStore<TUser>接口?
- 防止在ASP中缓存。NET MVC中使用属性的特定操作
- 在ASP .NET身份声明是什么
- 如果我使用OWIN Startup.cs类并将所有配置移动到那里,我是否需要一个Global.asax.cs文件?
- ASP。NET Identity DbContext混淆
- jQuery Ajax调用和Html.AntiForgeryToken()
- 把内容放在HttpResponseMessage对象?
- asp.net MVC中的@RenderSection是什么
- 在哪里放置AutoMapper.CreateMaps?
- 我如何提高ASP。NET MVC应用程序性能?
- 如何在剃刀视图上引用.css文件?
- 获取“JSON请求太大,无法反序列化”