【发布时间】:2014-03-11 09:20:56
【问题描述】:
我正在对名为 Estatement 的 ActionResult 方法进行 Ajax 调用。 这就是我想要发生的事情
如果 checkUser = false,则应该重定向到视图
如果 checkuser 不为 false,我想成功返回 Done 并使用我的 ajax 代码做点什么。
现在我无法重定向到语句视图,我得到的只是来自错误消息的警报(尝试处理此错误时发生错误)
你认为这段代码有什么问题?
<div class="eStmnt">
<div class="eStmntAd">
<h3>Go Green!</h3>
</div>
<p class="eStmntAffirm hide">Testing Testing</p>
</div>
<script type="text/javascript">
$(".eStmnt").click(function() {
$.ajax({
type: "POST",
url: '@Url.Action("Estatement","MyController")',
dataType: "json",
success:function(result) {
if (result == "Done") {
$(".eStmntAffirm").removeClass("hide").addClass("show");
}
},
error: function() {
alert('An error occured while trying to process this');
}
});
});
</script>
public ActionResult Estatement()
{
bool checkUser = false;
string result = string.Empty;
if (checkUser == false)
{
return RedirectToAction("Statement","MyProducts");
}
result = "Done";
return Json(result);
}
【问题讨论】:
标签: jquery asp.net-mvc asp.net-mvc-4