在ASP的最新(RC1)版本中。NET MVC,我怎么得到Html。ActionLink渲染为按钮或图像而不是链接?
当前回答
这是我在没有脚本的情况下做到的:
@using (Html.BeginForm("Action", "Controller", FormMethod.Get))
{
<button type="submit"
class="btn btn-default"
title="Action description">Button Label</button>
}
相同,但有参数和确认对话框:
@using (Html.BeginForm("Action", "Controller",
new { paramName = paramValue },
FormMethod.Get,
new { onsubmit = "return confirm('Are you sure?');" }))
{
<button type="submit"
class="btn btn-default"
title="Action description">Button Label</button>
}
其他回答
甚至后来的反应,但我只是遇到了一个类似的问题,最终写我自己的图像链接HtmlHelper扩展。
你可以在我的博客上面的链接中找到它的实现。
只是为了防止有人在寻找一个实现。
<按钮onclick = " href = "位置。行动(“新客户”、“顾客”)'
我所做的是将actionLink和图像分开。 将actionlink图像设置为隐藏 然后添加了jQuery触发器调用。这更像是一种变通方法。
'<%= Html.ActionLink("Button Name", "Index", null, new { @class="yourclassname" }) %>'
<img id="yourImage" src="myImage.jpg" />
触发的例子:
$("#yourImage").click(function () {
$('.yourclassname').trigger('click');
});
使用bootstrap,这是创建控制器动作链接的最短和最干净的方法,该控制器动作以动态按钮的形式出现:
<a href='@Url.Action("Action", "Controller")' class="btn btn-primary">Click Me</a>
或者使用Html helper:
@Html.ActionLink("Click Me", "Action", "Controller", new { @class = "btn btn-primary" })
这是我在没有脚本的情况下做到的:
@using (Html.BeginForm("Action", "Controller", FormMethod.Get))
{
<button type="submit"
class="btn btn-default"
title="Action description">Button Label</button>
}
相同,但有参数和确认对话框:
@using (Html.BeginForm("Action", "Controller",
new { paramName = paramValue },
FormMethod.Get,
new { onsubmit = "return confirm('Are you sure?');" }))
{
<button type="submit"
class="btn btn-default"
title="Action description">Button Label</button>
}
推荐文章
- 从控制器内获得控制器和动作名称?
- _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请求太大,无法反序列化”