Yes, you can do this with @Html.ActionLink
as AliRıza Adıyahşi has commented.
Subscribe to the onclick
event of the @Html.ActionLink
Here is the implementation:
@Html.ActionLink("Click here","ActionName","ControllerName",new { @onclick="return Submit();"})
And in javascript write the confirm
box.
<script type="text/javascript">
function Submit() {
if (confirm("Are you sure you want to submit ?")) {
return true;
} else {
return false;
}
}
</script>
Edit
Try like this:
<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" })
Now in your controller do some operations based on the isTrue
querystring
public ActionResult Somemethod(bool isTrue)
{
if (isTrue)
{
//do something
}
else
{
//do something
}
return View();
}