你可以,如果用户确认,然后链接参数将传递给控制器的操作方法与ActionLink的
@Html.ActionLink(
"Delete",
"DeleteAction",
"Product",
new { confirm = true, other_parameter = "some_more_parameter" },
new { onclick = "return confirm('Do you really want to delete this product?')" })
做到这一点。
public ActionResult DeleteAction(bool confirm, string other_parameter)
{
// if user confirm to delete then this action will fire
// and you can pass true value. If not, then it is already not confirmed.
return View();
}
更新
您不能显示消息框在控制器端。但你可以做到这一点像下面
public ActionResult ActionName(passing value)
{
// some code
message box here
if (true){ ViewBag.Status = true }
else { ViewBag.Status = false}
return View();
}
,并查看
<script type="text/javascript">
function() {
var status = '@ViewBag.Status';
if (status) {
alert("success");
} else {
alert("error");
}
}
</script>
但所有这些代码是不优雅的方式。这是你的scenerio的解决方案。
你可以用Html.ActionLink ... – 2013-03-21 12:56:10
做到这一点。我在我的控制器中使用这个值有一些价值,我需要执行一些操作。另一种选择:将请求发送到服务器端并将yes或no值传递给服务器使用此操作我们将执行一些操作 – user279stack1 2013-03-21 12:59:04
@ user279stack1您尝试过什么?你做了什么代码? – 2013-03-21 13:00:59