我想使用按钮而不是ActionLink重写下面的代码。任何帮助将不胜感激。感谢。
@Html.ActionLink("Test Link","Index", "Home", new { id = item.id})
是否有可能写下面的内容或有更好的方法吗?我也不确定语法,所以请随时纠正它。
<input type="button" value="Submit" onclick="location.href='@Url.Action("Index", "Home", new { id = @Model.FirstorDefault.Id.ToString()}, null)'" />
答案 0 :(得分:7)
将其写为锚标记,因为您似乎想要在单击按钮时重定向用户。如果您愿意,可以轻松地将锚设置为按钮的样式。
<a href="@Url.Action("Index", "Home",
new { id = Model.FirstorDefault.Id.ToString()})">Submit</a>
现在“提交”标题毫无意义,因为您现在正在执行“GET”操作而不是“POST”。但如果你坚持使用按钮,你可以这样做:
<input type="button" value="Submit" id="btn1" />
// just replace zero with whatever value you need to use
$("#btn1").click(function () {
window.location.replace('@Url.Action("about", "Home", new { id = 0 })');
});
答案 1 :(得分:0)
<form method="get"action="/Home/Index/@Model.id">
<input id="Submit1" type="submit" value="submit" />
</form>