我有一个操作方法 VerifyNewUser(),当用户单击其电子邮件中的 url(注册验证 url)时会调用该方法。
action 方法在 ViewBag 中设置一个 bool 属性,将用户更新为经过验证的用户,然后我加载主页,用户自动登录。在 /Home/Index 视图中,我想检查 ViewBag 中我设置的属性如果为真,则显示一个 jquery ui 对话框。
但是,我的 ViewBag 为 null 并且脚本被跳过。注意我将消息存储在 homeController.ViewBag 中,所以我认为这会起作用。也许没有 ViewBag 有更好的方法来做到这一点?
public ActionResult VerifyNewUser()
{
if(everything checks out)
{
HomeController homeController = new HomeController();
homeController.ViewBag.RegisterationLoad = true;
homeController.ViewBag.VerificationMessage = "Thank you! Your account has been activated";
return View("../Home/Index", null);
}
}
家庭控制器没什么特别的:
public ActionResult Index(){
return View();
}
在主页视图中,我有这段代码应该在单击验证 url 后检查主页是否正在加载,并且应该显示一个 jquery ui 对话框:
@if (ViewBag.RegistrationLoad == "true")
{
<script type="text/javascript">
$("<div></div>").html("<span>@ViewBag.VerificationMessage</span>").dialog({
width: 365, height: 165, minWidth: 365, minHeight: 165, maxWidth: 365, maxHeight: 165,
autoOpen: true, modal: true, dialogClass: 'noTitleDialog', position: "center",
buttons: {
"Ok": function () {
$(this).remove();
}
}
});
</script>
}
谢谢你的时间