在ASP的最新(RC1)版本中。NET MVC,我怎么得到Html。ActionLink渲染为按钮或图像而不是链接?
当前回答
<li><a href="@Url.Action( "View", "Controller" )"><i class='fa fa-user'></i><span>Users View</span></a></li>
显示带有链接的图标
其他回答
一个简单的方法做你的Html。ActionLink变成一个按钮(只要你插入了BootStrap -你可能有)是这样的:
@Html.ActionLink("Button text", "ActionName", "ControllerName", new { @class = "btn btn-primary" })
@using (Html.BeginForm("DeleteMember", "Member", new { id = Model.MemberID }))
{
<input type="submit" value="Delete Member" onclick = "return confirm('Are you sure you want to delete the member?');" />
}
借用帕特里克的回答,我发现我必须这样做:
<button onclick="location.href='@Url.Action("Index", "Users")';return false;">Cancel</button>
避免调用表单的post方法。
这是一个很晚的回答,但这是我如何将ActionLink变成一个按钮的。我们在我们的项目中使用Bootstrap,因为它很方便。不要介意@T,因为它只是我们使用的一个翻译器。
@Html.Actionlink("Some_button_text", "ActionMethod", "Controller", "Optional parameter", "html_code_you_want_to_apply_to_the_actionlink");
上面给出了一个如下图所示的链接:
localhost:XXXXX/Firms/AddAffiliation/F0500
在我看来:
@using (Html.BeginForm())
{
<div class="section-header">
<div class="title">
@T("Admin.Users.Users")
</div>
<div class="addAffiliation">
<p />
@Html.ActionLink("" + @T("Admin.Users.AddAffiliation"), "AddAffiliation", "Firms", new { id = (string)@WorkContext.CurrentFirm.ExternalId }, new { @class="btn btn-primary" })
</div>
</div>
}
希望这对大家有所帮助
你可以说我过于简单,但我就是这么做的:
<a href="<%: Url.Action("ActionName", "ControllerName") %>">
<button>Button Text</button>
</a>
你只需要处理超链接突出显示。我们的用户喜欢它:)
推荐文章
- 防止在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请求太大,无法反序列化”
- 存储库和服务层的区别?
- 在ASP中实现请求节流的最佳方法。净MVC吗?
- 如何添加ID属性Html.BeginForm()在asp.net mvc?
- 什么是MvcHtmlString,什么时候我应该使用它?