@Html.ActionLink
是的,正如 AliRıza Adıyahşi 所评论的那样,您可以这样做。
订阅该onclick
事件@Html.ActionLink
这是实现:
@Html.ActionLink("Click here","ActionName","ControllerName",new { @onclick="return Submit();"})
并在 javascript 中编写该confirm
框。
<script type="text/javascript">
function Submit() {
if (confirm("Are you sure you want to submit ?")) {
return true;
} else {
return false;
}
}
</script>
编辑
试试这样:
<script type="text/javascript">
function Submit() {
if (confirm("Are you sure you want to submit ?")) {
document.getElementById('anchortag').href += "?isTrue=true";
} else {
document.getElementById('anchortag').href += "?isTrue=false";
}
return true;
}
</script>
@Html.ActionLink("Submit", "Somemethod", "Home", new { @onclick = "return Submit();", id = "anchortag" })
现在在您的控制器中根据isTrue
查询字符串执行一些操作
public ActionResult Somemethod(bool isTrue)
{
if (isTrue)
{
//do something
}
else
{
//do something
}
return View();
}