在ASP的最新(RC1)版本中。NET MVC,我怎么得到Html。ActionLink渲染为按钮或图像而不是链接?


当前回答

如果你不想使用链接,使用按钮。你也可以添加图片到按钮:

<button type="button" onclick="location.href='@Url.Action("Create", "Company")'" >
   Create New
   <img alt="New" title="New" src="~/Images/Button/plus.png">
</button>

Type ="button"执行你的动作而不是提交表单。

其他回答

你不能用Html.ActionLink这样做。你应该使用Url。RouteUrl并使用该URL来构造所需的元素。

甚至后来的反应,但我只是遇到了一个类似的问题,最终写我自己的图像链接HtmlHelper扩展。

你可以在我的博客上面的链接中找到它的实现。

只是为了防止有人在寻找一个实现。

一个简单的方法做你的Html。ActionLink变成一个按钮(只要你插入了BootStrap -你可能有)是这样的:

@Html.ActionLink("Button text", "ActionName", "ControllerName", new { @class = "btn btn-primary" })

很简单:

<button onclick="@Url.Action("index", "Family", new {familyid = Model.FamilyID })">Cancel</button>

你可以说我过于简单,但我就是这么做的:

<a href="<%: Url.Action("ActionName", "ControllerName") %>">
    <button>Button Text</button>
</a>

你只需要处理超链接突出显示。我们的用户喜欢它:)